Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: How to concatenate N binary buffers?

by AnomalousMonk (Monsignor)
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 contemplating the Monastery: (7)
As of 2014-08-29 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls