Subject: | Multiple issues with bzinflate |
bzinflate seems to have a couple of issues.
1) The docs say $buffer may be a scalar or a scalar reference. However,
scalar reference doesn't work: it returns a magic error.
2) None of my inflate attempts end up returning BZ_OK or BZ_STREAM_END.
Instead, on apparently _successful_ bzinflate calls (where $outbuf
contains sane data), I always get "IO_ERROR (-6): 11 Resource
temporarily unavailable"
The attached patch makes the test suite test these issues (and currently
fail), and while at it adds $status checks for bzinflateInit() and
bzclose().
This is on Fedora 10 x86_64, perl v5.10.0, system bzip2 1.0.5.
Subject: | Compress-Bzip2-inflate.patch |
diff -up Compress-Bzip2-2.09/t/060-inflate.t~ Compress-Bzip2-2.09/t/060-inflate.t
--- Compress-Bzip2-2.09/t/060-inflate.t~ 2005-04-26 17:17:07.000000000 +0300
+++ Compress-Bzip2-2.09/t/060-inflate.t 2009-07-23 23:08:12.000000000 +0300
@@ -1,6 +1,6 @@
# -*- mode: perl -*-
-use Test::More tests => 4;
+use Test::More tests => 5;
#use Test::More qw(no_plan);
## stream uncompress sample2 from the bzip2 1.0.2 distribution
@@ -18,22 +18,22 @@ my $INFILE = catfile( qw(bzlib-src sampl
( my $MODELFILE = $INFILE ) =~ s/\.bz2$/.ref/;
my $PREFIX = catfile( qw(t 060-tmp) );
-my ( $in, $out, $d, $outbuf, $counter, $bytes, $bytesout );
+my ( $in, $out, $d, $outbuf, $status, $counter, $bytes, $bytesout );
open( $in, "< $INFILE" ) or die "$INFILE: $!";
open( $out, "> $PREFIX-out.txt" ) or die "$PREFIX-out.txt: $!";
## verbosity 0-4, small 0,1, blockSize100k 1-9, workFactor 0-250, readUncompressed 0,1
-$d = bzinflateInit( -verbosity => $debugf ? 4 : 0 );
+( $d, $status ) = bzinflateInit( -verbosity => $debugf ? 4 : 0 );
-ok( $d, "bzinflateInit was successful" );
+ok( $d && $status == BZ_OK, "bzinflateInit was successful" );
$counter = 0;
$bytes = 0;
$bytesout = 0;
while ( my $ln = sysread( $in, $buf, 512 ) ) {
- $outbuf = $d->bzinflate( $buf );
- if ( !defined($outbuf) ) {
+ ( $outbuf, $status ) = $d->bzinflate( $counter % 2 ? \$buf : $buf );
+ if ( $status != BZ_STREAM_END && $status != BZ_OK || !defined($outbuf) ) {
print STDERR "error: $outbuf $bzerrno\n";
last;
}
@@ -47,7 +47,9 @@ while ( my $ln = sysread( $in, $buf, 512
$counter++;
}
-$outbuf = $d->bzclose;
+( $outbuf, $status ) = $d->bzclose;
+ok( $status == BZ_OK, "bzclose was successful" );
+
if ( defined($outbuf) && $outbuf ne '' ) {
syswrite( $out, $outbuf );
$bytesout += length($outbuf);