Gunzip using Compress::Zlib in Perl
9
The docs for Compress::Zlib for perl are very complex. But, the most simple use of the Module is not too bad. I've waded through the perdoc so you don't have to.
Gunzip.pl is here. I will let you know when I have Gzip.pl done.
You can do something more interesting with "success" variable.
Gunzip.pl is here. I will let you know when I have Gzip.pl done.
You can do something more interesting with "success" variable.
use strict;
use Compress::Zlib;
my $infile = $ARGV[0];
my $outfile = $ARGV[1];
if (! $infile || ! $outfile) {
print "$0 <infile> <outfile>\n";
exit;
}
my $buffer;
my $gz = undef;
my $success = 1;
if (! open FH, "> $outfile") {
$success = 0;
print "Unable to write to '$outfile'\n";
}
else {
binmode FH;
print "GZ File = '$infile'\n";
print "OUT File = '$outfile'\n";
if ($gz = gzopen($infile, "rb")) {
while ($gz->gzread($buffer) > 0) {
print FH $buffer;
}
if ($gzerrno != Z_STREAM_END) {
$success = 0;
print "ZLib Error: reading $outfile - $gzerrno: $!\n";
}
else {
$success = 1;
}
$gz->gzclose;
}
else {
$success = 0;
print "ZLib Error: opening $infile - $gzerrno: $!\n";
}
close FH;
}






There are currently no comments for this snippet.