GZip a file using Perl
7
Need to GZip a file using Perl?
Use Compress::Zlib.
This is a simple perl script which creates a GZip file.
Use Compress::Zlib.
This is a simple perl script which creates a GZip file.
use strict;
use Compress::Zlib;
my $file = $ARGV[0];
if (! $file) {
print "$0 <file>\n";
exit;
}
my $gzfile = $file.".gz";
open (FILE, $file);
binmode FILE;
my $buf;
my $gz = gzopen($gzfile, "wb");
if (! $gz) {
print "Unable to write $gzfile $!\n";
exit;
}
else {
while (my $by = sysread (FILE, $buf, 4096)) {
if (! $gz->gzwrite($buf)) {
print "Zlib error writing to $gzfile: $gz->gzerror\n";
exit;
}
}
$gz->gzclose();
print "'$file' GZipped to '$gzfile'\n";
}






There are currently no comments for this snippet.