Created
June 1, 2012 14:08
-
-
Save kentfredric/2852411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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