From: Paul Marquess Date: Mon, 17 Apr 2006 10:58:30 +0000 (+0100) Subject: Compress::Zlib X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9871907771ef3e9abb9c858120e90de0ee642509;p=p5sagit%2Fp5-mst-13.2.git Compress::Zlib From: "Paul Marquess" Message-ID: <019b01c66205$7dc7ea50$6601a8c0@myopwv.com> p4raw-id: //depot/perl@27861 --- diff --git a/ext/Compress/Zlib/lib/Compress/Zlib.pm b/ext/Compress/Zlib/lib/Compress/Zlib.pm index 797e90a..a82021a 100644 --- a/ext/Compress/Zlib/lib/Compress/Zlib.pm +++ b/ext/Compress/Zlib/lib/Compress/Zlib.pm @@ -158,14 +158,16 @@ sub Compress::Zlib::gzFile::gzread return _set_gzerr(Z_STREAM_ERROR()) if $self->[1] ne 'inflate'; - if ($self->gzeof()) { + my $len = defined $_[1] ? $_[1] : 4096 ; + + if ($self->gzeof() || $len == 0) { # Zap the output buffer to match ver 1 behaviour. $_[0] = "" ; return 0 ; } my $gz = $self->[0] ; - my $status = $gz->read($_[0], defined $_[1] ? $_[1] : 4096) ; + my $status = $gz->read($_[0], $len) ; _save_gzerr($gz, 1); return $status ; } diff --git a/ext/Compress/Zlib/t/14gzopen.t b/ext/Compress/Zlib/t/14gzopen.t index d4a3a0d..bade158 100644 --- a/ext/Compress/Zlib/t/14gzopen.t +++ b/ext/Compress/Zlib/t/14gzopen.t @@ -20,7 +20,7 @@ BEGIN { $extra = 1 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - plan tests => 210 + $extra ; + plan tests => 217 + $extra ; use_ok('Compress::Zlib', 2) ; use_ok('IO::Compress::Gzip::Constants') ; @@ -577,3 +577,24 @@ foreach my $stdio ( ['-', '-'], [*STDIN, *STDOUT]) eval { $u->gzseek(-1, SEEK_CUR) ; }; like $@, mkErr("gzseek: cannot seek backwards"); } + +{ + title "gzread ver 1.x compat -- the output buffer is always zapped."; + my $lex = new LexFile my $name ; + + my $a = gzopen($name, "w"); + $a->gzwrite("fred"); + $a->gzclose ; + + my $u = gzopen($name, "r"); + + my $buf1 ; + is $u->gzread($buf1, 0), 0, " gzread returns 0"; + ok defined $buf1, " output buffer defined"; + is $buf1, "", " output buffer empty string"; + + my $buf2 = "qwerty"; + is $u->gzread($buf2, 0), 0, " gzread returns 0"; + ok defined $buf2, " output buffer defined"; + is $buf2, "", " output buffer empty string"; +}