Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to concatenate N binary buffers?

by AnomalousMonk (Abbot)
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;


Comment on Re^2: How to concatenate N binary buffers?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-21 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (171 votes), past polls