in reply to Re^2: Advice needed on chunked read + byte-range logic
in thread Advice needed on chunked read + byte-range logic
my $chunk_size = $cnf->{chunk_size} || 1024; my $bytes_in = $cnf->{bytes_in} || 0; my $bytes_out= $cnf->{bytes_out} || undef; my $pos = $bytes_in; binmode($fh); seek($fh,$bytes_in,0); while ( read( $fh, my $buffer, $chunk_size ) ) { $pos += $chunk_size; # alt.: += length($buffer) if( defined($bytes_out) && $pos > $bytes_out){ print substr($buffer, 0, ($chunk_size - ($pos - $bytes_o +ut)) ); # make last chunk shorter last; }elsif( defined($bytes_out) && $pos == $bytes_out){ print $buffer; last; }else{ print $buffer; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Advice needed on chunked read + byte-range logic
by ikegami (Patriarch) on Aug 27, 2010 at 22:20 UTC |