in reply to Re: Advice needed on chunked read + byte-range logic
in thread Advice needed on chunked read + byte-range logic
Why bytes::substr? Do you expect read to return something other than bytes? If so, you should make it so it doesn't (by using binmode) rather than attempting to work around it (by using bytes::substr).
The following leaves the file pointer at the same spot as your code:
seek($fh, $bytes_in, SEEK_SET) or die($!); my $to_read = $bytes_out-$bytes_in; while ($to_read > 0) { my $rv = read($fh, my $buffer, $chunk_size); die($!) if !defined($rv); die("Premature eof") if !$rv; substr($buffer, $to_read) = '' if $rv > $to_read; print($buffer); $to_read -= $bytes; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Advice needed on chunked read + byte-range logic
by isync (Hermit) on Aug 27, 2010 at 19:05 UTC | |
by ikegami (Patriarch) on Aug 27, 2010 at 22:20 UTC |