If the file you are going to copy is just a bunch of bits, then you should do something like this to just completely ignore any such bytes:
The above says that I'm opening the $out file and I'm just gonna send bits to it! This next part does the copy..$out = "output_path"; open (OUTBIN, '>',"$out") || die "unable to open $out"; binmode(OUTBIN) || die "unable to set binmode $out";
The above says: open filepath $x, then set it for binary read. Each read will be 8*2**10 or 8 * 1024= 8192 bytes. Perl will help out here as it keeps track of the number of bytes in $buff. If the $buff has less than what you expect for the maximum read, this is no problem!open(INBIN, "<$x") || die "unable to open $x"; binmode(INBIN) || die "unable to set binmode $x"; while (read(INBIN, my $buff, 8 * 2**10)) { print OUTBIN $buff; } close(INBIN) || die "unable to close inbin"; close(OUTBIN) || die "unable to close outbin";
2**10=1024 is a "magic number" for the hardware.
A typical Unix system will read from the hard drive in increments of 4x that or 4096 bytes. Here the buffer size
is twice that or 8192 bytes. It is counter-intuitive, but increasing the buffer size can actually slow things down if you have a smart disk system.
The important part is to set BINMODE. And for the read, you will have to specify a size that should be in increments of 1024 (a magic number).
In reply to Re: bin mode file copy
by Marshall
in thread bin mode file copy
by smanicka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |