Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to concatenate N binary buffers?

by AnomalousMonk (Canon)
on Nov 13, 2012 at 17:57 UTC ( #1003682=note: print w/replies, xml ) Need Help??


in reply to Re: How to concatenate N binary buffers?
in thread How to concatenate N binary buffers?

    syswrite $out, $buf1, $bufsize;
    syswrite $out, $buf2, $bufsize;

If a constant number  $bufsize of bytes is always written, then when fewer than  $bufsize bytes are read, typically at the end of a file, a block of junk will be written to the output file between the  $buf1 and  $buf2 blocks (Update: and also from the end of  $buf2 to the end of the output file).

Better to follow choroba's advice and record the bytes actually read, then write just that number of bytes (but still without the need for explicit concatenation):
    syswrite $out, $buf1, $size1;
    syswrite $out, $buf2, $size2;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003682]
help
Chatterbox?
What's the matter? Cat got your tongue?...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2016-12-06 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (115 votes). Check out past polls.