This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Compress::Zlib
[perl5.git] / ext / Compress / Zlib / examples / gzcat
index 5572bae..3bbd297 100755 (executable)
@@ -1,29 +1,30 @@
 #!/usr/local/bin/perl
 
-use IO::Uncompress::Gunzip qw( $GunzipError );
 use strict ;
 use warnings ;
 
+use Compress::Zlib ;
+
 #die "Usage: gzcat file...\n"
 #    unless @ARGV ;
 
-my $file ;
-my $buffer ;
-my $s;
+my $filename ;
 
 @ARGV = '-' unless @ARGV ;
 
-foreach $file (@ARGV) {
-    
-    my $gz = new IO::Uncompress::Gunzip $file
-         or die "Cannot open $file: $GunzipError\n" ;
+foreach my $filename (@ARGV) {
+    my $buffer ;
+
+    my $file = $filename ;
+    $file = \*STDIN if $file eq '-' ;
 
-    print $buffer
-        while ($s = $gz->read($buffer)) > 0 ;
+    my $gz = gzopen($file, "rb") 
+         or die "Cannot open $file: $gzerrno\n" ;
 
-    die "Error reading from $file: $GunzipError\n" 
-        if $s < 0 ;
+    print $buffer while $gz->gzread($buffer) > 0 ;
+
+    die "Error reading from $filename: $gzerrno" . ($gzerrno+0) . "\n" 
+        if $gzerrno != Z_STREAM_END ;
     
-    $gz->close() ;
+    $gz->gzclose() ;
 }
-