diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-05-05 12:09:48 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-05-05 12:18:11 +0200 |
commit | 9de654f174a7c7ca88031e2ac4a33add560d0c8c (patch) | |
tree | 7763181344f0e6240e96c5a444c8a5b57c986dc8 /ext/IO-Compress/examples/io/gzip | |
parent | f1bef09e9115ebdc1c8818193d6c4cbb8bc050e6 (diff) | |
parent | 216e7dec1076aa94d5b8331c187c135e4952955a (diff) | |
download | perl-9de654f174a7c7ca88031e2ac4a33add560d0c8c.tar.gz |
Merge branch 'blead' into smartmatch
Conflicts:
t/op/switch.t
Diffstat (limited to 'ext/IO-Compress/examples/io/gzip')
-rw-r--r-- | ext/IO-Compress/examples/io/gzip/gzappend | 24 | ||||
-rwxr-xr-x | ext/IO-Compress/examples/io/gzip/gzcat | 29 | ||||
-rwxr-xr-x | ext/IO-Compress/examples/io/gzip/gzgrep | 40 | ||||
-rwxr-xr-x | ext/IO-Compress/examples/io/gzip/gzstream | 24 |
4 files changed, 117 insertions, 0 deletions
diff --git a/ext/IO-Compress/examples/io/gzip/gzappend b/ext/IO-Compress/examples/io/gzip/gzappend new file mode 100644 index 0000000000..a4a60a9aad --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzappend @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl + +use IO::Compress::Gzip qw( $GzipError ); +use strict ; +use warnings ; + +die "Usage: gzappend gz-file file...\n" + unless @ARGV ; + + +my $output = shift @ARGV ; + +@ARGV = '-' unless @ARGV ; + +my $gz = new IO::Compress::Gzip $output, Merge => 1 + or die "Cannot open $output: $GzipError\n" ; + +$gz->write( [@ARGV] ) + or die "Cannot open $output: $GzipError\n" ; + +$gz->close; + + + diff --git a/ext/IO-Compress/examples/io/gzip/gzcat b/ext/IO-Compress/examples/io/gzip/gzcat new file mode 100755 index 0000000000..5572bae959 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzcat @@ -0,0 +1,29 @@ +#!/usr/local/bin/perl + +use IO::Uncompress::Gunzip qw( $GunzipError ); +use strict ; +use warnings ; + +#die "Usage: gzcat file...\n" +# unless @ARGV ; + +my $file ; +my $buffer ; +my $s; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + + my $gz = new IO::Uncompress::Gunzip $file + or die "Cannot open $file: $GunzipError\n" ; + + print $buffer + while ($s = $gz->read($buffer)) > 0 ; + + die "Error reading from $file: $GunzipError\n" + if $s < 0 ; + + $gz->close() ; +} + diff --git a/ext/IO-Compress/examples/io/gzip/gzgrep b/ext/IO-Compress/examples/io/gzip/gzgrep new file mode 100755 index 0000000000..33820ba064 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzgrep @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use strict ; +use warnings ; +use IO::Uncompress::Gunzip qw($GunzipError); + +die "Usage: gzgrep pattern [file...]\n" + unless @ARGV >= 1; + +my $pattern = shift ; +my $file ; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + my $gz = new IO::Uncompress::Gunzip $file + or die "Cannot uncompress $file: $GunzipError\n" ; + + while (<$gz>) { + print if /$pattern/ ; + } + + die "Error reading from $file: $GunzipError\n" + if $GunzipError ; +} + +__END__ +foreach $file (@ARGV) { + my $gz = gzopen($file, "rb") + or die "Cannot open $file: $gzerrno\n" ; + + while ($gz->gzreadline($_) > 0) { + print if /$pattern/ ; + } + + die "Error reading from $file: $gzerrno\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; +} diff --git a/ext/IO-Compress/examples/io/gzip/gzstream b/ext/IO-Compress/examples/io/gzip/gzstream new file mode 100755 index 0000000000..9d03bc5749 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzstream @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; +use IO::Compress::Gzip qw(gzip $GzipError); + +gzip '-' => '-', Minimal => 1 + or die "gzstream: $GzipError\n" ; + +#exit 0; + +__END__ + +#my $gz = new IO::Compress::Gzip *STDOUT +my $gz = new IO::Compress::Gzip '-' + or die "gzstream: Cannot open stdout as gzip stream: $GzipError\n" ; + +while (<>) { + $gz->write($_) + or die "gzstream: Error writing gzip output stream: $GzipError\n" ; +} + +$gz->close + or die "gzstream: Error closing gzip output stream: $GzipError\n" ; |