in reply to Advice needed on chunked read + byte-range logic
bugs fixed: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; 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 bytes::substr($buffer, 0, ($chunk_size - ($pos - $ +bytes_out)) ); # make last chunk shorter last; }elsif( defined($bytes_out) && $pos == $bytes_out){ print $buffer; last; }else{ print $buffer; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Advice needed on chunked read + byte-range logic
by ikegami (Patriarch) on Aug 26, 2010 at 01:38 UTC | |
by isync (Hermit) on Aug 27, 2010 at 19:05 UTC | |
by ikegami (Patriarch) on Aug 27, 2010 at 22:20 UTC |