Subject: | bzinflate() returns BZ_IO_ERROR |
Date: | Thu, 27 Jul 2017 20:21:13 +0000 |
To: | bug-Compress-Bzip2 [...] rt.cpan.org |
From: | Steve Grazzini <steve.grazzini [...] grantstreet.com> |
Hello,
bzinflate always returns the error BZ_IO_ERROR, which means that none of
the example code for the streaming interface actually works.
I think that t/060-inflate.t anticipates the actual behavior:
while ( my $ln = sysread( $in, $buf, 512 ) ) {
# test buf as scalar or scalarref
( $outbuf, $status ) = $d->bzinflate( $counter % 2 ? \$buf : $buf );
# the 2nd attempt to read from the 512 buf in bzfile_streambuf_read
will cause a BZ_IO_ERROR
if ( $status != BZ_IO_ERROR && $status != BZ_STREAM_END && $status !=
BZ_OK || !defined($outbuf) ) {
diag "error: $outbuf $bzerrno\n";
last;
}
But I'm not sure that it's correct to do so. Ideally, I think the library
should be fixed to suppress that error in this context. But, if that's not
practical, the documentation should be fixed to show the necessary checks
for BZ_IO_ERROR. For example, the bzcat implementation needs to be:
my ($output, $status) ;
while (read(STDIN, $input, 4096))
{
($output, $status) = $x->bzinflate(\$input) ;
print $output
if $status == BZ_OK or $status == BZ_STREAM_END or $status ==
BZ_IO_ERROR;
last if $status != BZ_OK and $status != BZ_IO_ERROR;
}
die "inflation failed\n"
unless $status == BZ_STREAM_END
or $status == BZ_IO_ERROR;
Thanks!