| 38255 |      1 | #!/usr/bin/env perl
 | 
|  |      2 | #
 | 
|  |      3 | # Author: Makarius
 | 
|  |      4 | #
 | 
|  |      5 | # raw_dump - direct copy without extra buffering
 | 
|  |      6 | #
 | 
|  |      7 | 
 | 
|  |      8 | use warnings;
 | 
|  |      9 | use strict;
 | 
|  |     10 | 
 | 
|  |     11 | use IO::File;
 | 
|  |     12 | 
 | 
|  |     13 | 
 | 
|  |     14 | # args
 | 
|  |     15 | 
 | 
|  |     16 | my ($input, $output) = @ARGV;
 | 
|  |     17 | 
 | 
|  |     18 | 
 | 
|  |     19 | # prepare files
 | 
|  |     20 | 
 | 
|  |     21 | my $infile;
 | 
|  |     22 | my $outfile;
 | 
|  |     23 | 
 | 
|  |     24 | if ($input eq "-") { $infile = *STDIN; }
 | 
|  |     25 | else {
 | 
|  |     26 |   $infile = new IO::File $input, "r";
 | 
|  |     27 |   defined $infile || die $!;
 | 
|  |     28 | }
 | 
|  |     29 | 
 | 
|  |     30 | if ($output eq "-") { $outfile = *STDOUT; }
 | 
|  |     31 | else {
 | 
|  |     32 |   $outfile = new IO::File $output, "w";
 | 
|  |     33 |   defined $outfile || die $!;
 | 
|  |     34 | }
 | 
|  |     35 | 
 | 
|  |     36 | binmode $infile;
 | 
|  |     37 | binmode $outfile;
 | 
|  |     38 | 
 | 
|  |     39 | 
 | 
|  |     40 | # main loop
 | 
|  |     41 | 
 | 
|  |     42 | my $chunk;
 | 
|  |     43 | while ((sysread $infile, $chunk, 65536), length $chunk > 0) {
 | 
|  |     44 |   my $end = length $chunk;
 | 
|  |     45 |   my $offset = 0;
 | 
|  |     46 |   while ($offset < $end) {
 | 
|  |     47 |     $offset += syswrite $outfile, $chunk, $end - $offset, $offset;
 | 
|  |     48 |   }
 | 
|  |     49 | }
 | 
|  |     50 | 
 | 
|  |     51 | 
 | 
|  |     52 | # cleanup
 | 
|  |     53 | 
 | 
|  |     54 | undef $infile;
 | 
|  |     55 | undef $outfile;
 | 
|  |     56 | 
 |