diff options
author | Steve Peters <steve@fisharerojo.org> | 2007-03-06 16:49:47 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2007-03-06 16:49:47 +0000 |
commit | 82d8f8347aac1265a123c7171e3613e510568391 (patch) | |
tree | b41c0db5e584eff4ac738a9ec61b0ac0b7778f95 /lib | |
parent | 45cbc99acbccce79a366aa4654806e11e6e67d42 (diff) | |
download | perl-82d8f8347aac1265a123c7171e3613e510568391.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/IO/Zlib.pm | 35 | ||||
-rw-r--r-- | lib/IO/Zlib/t/basic.t | 20 | ||||
-rw-r--r-- | lib/IO/Zlib/t/getline.t | 38 |
3 files changed, 51 insertions, 42 deletions
diff --git a/lib/IO/Zlib.pm b/lib/IO/Zlib.pm index d1b54c3460..f4a15ceddf 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 2df2b8c096..fc8da72797 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 = <<EOM ; hello world @@ -37,13 +37,17 @@ ok(6, $file = IO::Zlib->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 4e0d14543d..237160bc9f 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 = (<<EOM, <<EOM, <<EOM, <<EOM) ; this is line 1 @@ -39,22 +39,26 @@ ok(2, $file->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); |