From: Steve Peters Date: Tue, 6 Mar 2007 16:49:47 +0000 (+0000) Subject: Upgrade to IO-Zlib-1.05. There are updates to the core that have X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82d8f8347aac1265a123c7171e3613e510568391;p=p5sagit%2Fp5-mst-13.2.git Upgrade to IO-Zlib-1.05. There are updates to the core that have not yet been included in the CPAN distribution, so the core module has a version bump. p4raw-id: //depot/perl@30489 --- diff --git a/lib/IO/Zlib.pm b/lib/IO/Zlib.pm index d1b54c3..f4a15ce 100644 --- a/lib/IO/Zlib.pm +++ b/lib/IO/Zlib.pm @@ -6,7 +6,7 @@ package IO::Zlib; -$VERSION = "1.04_02"; +$VERSION = "1.05_01"; =head1 NAME @@ -256,10 +256,6 @@ No filename, no open. We must know how much to read. -=item IO::Zlib::READ: OFFSET is not supported - -Offsets of gzipped streams are not supported. - =item IO::Zlib::WRITE: too long LENGTH The LENGTH must be less than or equal to the buffer size. @@ -389,6 +385,7 @@ sub _alias { *IO::Handle::gzread = \&gzread_external; *IO::Handle::gzwrite = \&gzwrite_external; *IO::Handle::gzreadline = \&gzreadline_external; + *IO::Handle::gzeof = \&gzeof_external; *IO::Handle::gzclose = \&gzclose_external; $gzip_used = 1; } else { @@ -398,6 +395,7 @@ sub _alias { *gzread = \&Compress::Zlib::gzread; *gzwrite = \&Compress::Zlib::gzwrite; *gzreadline = \&Compress::Zlib::gzreadline; + *gzeof = \&Compress::Zlib::gzeof; } $aliased = 1; } @@ -438,7 +436,6 @@ sub OPEN croak "IO::Zlib::open: needs a filename" unless defined($filename); $self->{'file'} = gzopen($filename,$mode); - $self->{'eof'} = 0; return defined($self->{'file'}) ? $self : undef; } @@ -452,7 +449,6 @@ sub CLOSE my $status = $self->{'file'}->gzclose(); delete $self->{'file'}; - delete $self->{'eof'}; return ($status == 0) ? 1 : undef; } @@ -462,19 +458,16 @@ sub READ my $self = shift; my $bufref = \$_[0]; my $nbytes = $_[1]; - my $offset = $_[2]; + my $offset = $_[2] || 0; croak "IO::Zlib::READ: NBYTES must be specified" unless defined($nbytes); - croak "IO::Zlib::READ: OFFSET is not supported" if defined($offset) && $offset != 0; - return 0 if $self->{'eof'}; + $$bufref = "" unless defined($$bufref); - my $bytesread = $self->{'file'}->gzread($$bufref,$nbytes); + my $bytesread = $self->{'file'}->gzread(substr($$bufref,$offset),$nbytes); return undef if $bytesread < 0; - $self->{'eof'} = 1 if $bytesread < $nbytes; - return $bytesread; } @@ -505,17 +498,21 @@ sub WRITE my $length = shift; my $offset = shift; - croak "IO::Zlib::WRITE: too long LENGTH" unless $length <= length($buf); - croak "IO::Zlib::WRITE: OFFSET not supported" if defined($offset) && $offset != 0; + croak "IO::Zlib::WRITE: too long LENGTH" unless $offset + $length <= length($buf); - return $self->{'file'}->gzwrite(substr($buf,0,$length)); + return $self->{'file'}->gzwrite(substr($buf,$offset,$length)); } sub EOF { my $self = shift; - return $self->{'eof'}; + return $self->{'file'}->gzeof(); +} + +sub FILENO +{ + return undef; } sub new @@ -643,6 +640,10 @@ sub gzreadline_external { return defined $_[1] ? length($_[1]) : -1; } +sub gzeof_external { + return eof($_[0]); +} + sub gzclose_external { close($_[0]); # I am not entirely certain why this is needed but it seems diff --git a/lib/IO/Zlib/t/basic.t b/lib/IO/Zlib/t/basic.t index 2df2b8c..fc8da72 100644 --- a/lib/IO/Zlib/t/basic.t +++ b/lib/IO/Zlib/t/basic.t @@ -20,7 +20,7 @@ sub ok $name="test.gz"; -print "1..15\n"; +print "1..17\n"; $hello = <new()); ok(7, $file->open($name, "rb")); ok(8, !$file->eof()); ok(9, $file->read($uncomp, 1024) == length($hello)); -ok(10, $file->eof()); -ok(11, $file->opened()); -ok(12, $file->close()); -ok(13, !$file->opened()); +ok(10, $uncomp eq $hello); +ok(11, $file->eof()); +ok(12, $file->opened()); +ok(13, $file->close()); +ok(14, !$file->opened()); -unlink($name); +$file = IO::Zlib->new($name, "rb"); +ok(15, $file->read($uncomp, 1024, length($uncomp)) == length($hello)); +ok(16, $uncomp eq $hello . $hello); +$file->close(); -ok(14, $hello eq $uncomp); +unlink($name); -ok(15, !defined(IO::Zlib->new($name, "rb"))); +ok(17, !defined(IO::Zlib->new($name, "rb"))); diff --git a/lib/IO/Zlib/t/getline.t b/lib/IO/Zlib/t/getline.t index 4e0d145..237160b 100644 --- a/lib/IO/Zlib/t/getline.t +++ b/lib/IO/Zlib/t/getline.t @@ -20,7 +20,7 @@ sub ok $name="test.gz"; -print "1..19\n"; +print "1..23\n"; @text = (<print($text)); ok(3, $file->close()); ok(4, $file = IO::Zlib->new($name, "rb")); -ok(5, $file->getline() eq $text[0]); -ok(6, $file->getline() eq $text[1]); -ok(7, $file->getline() eq $text[2]); -ok(8, $file->getline() eq $text[3]); -ok(9, !defined($file->getline())); -ok(10, $file->close()); - -ok(11, $file = IO::Zlib->new($name, "rb")); +ok(5, !$file->eof()); +ok(6, $file->getline() eq $text[0]); +ok(7, $file->getline() eq $text[1]); +ok(8, $file->getline() eq $text[2]); +ok(9, $file->getline() eq $text[3]); +ok(10, !defined($file->getline())); +ok(11, $file->eof()); +ok(12, $file->close()); + +ok(13, $file = IO::Zlib->new($name, "rb")); +ok(14, !$file->eof()); eval '$file->getlines'; -ok(12, $@ =~ /^IO::Zlib::getlines: must be called in list context /); -ok(13, @lines = $file->getlines()); -ok(14, @lines == @text); -ok(15, $lines[0] eq $text[0]); -ok(16, $lines[1] eq $text[1]); -ok(17, $lines[2] eq $text[2]); -ok(18, $lines[3] eq $text[3]); -ok(19, $file->close()); +ok(15, $@ =~ /^IO::Zlib::getlines: must be called in list context /); +ok(16, @lines = $file->getlines()); +ok(17, @lines == @text); +ok(18, $lines[0] eq $text[0]); +ok(19, $lines[1] eq $text[1]); +ok(20, $lines[2] eq $text[2]); +ok(21, $lines[3] eq $text[3]); +ok(22, $file->eof()); +ok(23, $file->close()); unlink($name);