Skip to content

Instantly share code, notes, and snippets.

@kentfredric
Created June 1, 2012 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentfredric/2852411 to your computer and use it in GitHub Desktop.
Save kentfredric/2852411 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Compress::Zlib;
use Carp qw( croak );
inflate_file( $_ , *STDOUT ) for $ARGV[0];
sub inflate_file {
my ( $filename , $OFH ) = @_;
my ( $inflator, $status ) = Compress::Zlib::inflateInit or croak("Cannot create inflator: $@");
my $input = '';
open my $fh, '<', $filename or croak("Can't open $filename, $@ $! $?");
binmode $fh;
binmode $OFH;
my ( $output );
while ( read( $fh, $input, 4096 )) {
( $output , $status ) = $inflator->inflate( \$input );
print { $OFH } $output if $status == Compress::Zlib::Z_OK or $status == Compress::Zlib::Z_STREAM_END;
last if $status != Compress::Zlib::Z_OK;
}
croak( "Inflation failed of $filename , $@" ) unless $status == Compress::Zlib::Z_STREAM_END;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment