From 9871907771ef3e9abb9c858120e90de0ee642509 Mon Sep 17 00:00:00 2001 From: Paul Marquess Date: Mon, 17 Apr 2006 11:58:30 +0100 Subject: [PATCH] Compress::Zlib From: "Paul Marquess" Message-ID: <019b01c66205$7dc7ea50$6601a8c0@myopwv.com> p4raw-id: //depot/perl@27861 --- ext/Compress/Zlib/lib/Compress/Zlib.pm | 6 ++++-- ext/Compress/Zlib/t/14gzopen.t | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) 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"; +} -- 2.7.4