I am running on a w2k system, but need to be able to unzip text files that came from a unix system, and have been compressed there. i.e. file.txt.Z type files.
I have tried:
use Archive::Zip qw(AZ_OK);
my $zip = Archive::Zip->new();
unless ($zip -> read($zipfile) == AZ_OK) {
$status -> insert ('end', "Can not read file $zipfile!\nExiting!\n");
...
}
But it can't handle the .Z files. Is there another way, or module that is capable of doing this?
Thanks,
Spike.
The UNIX compress program uses a quite different implementation of the compression techniques used by zlib and gzip, so I'm not sure whether Compress::Zlib will be able to read .Z files.
Anyway, keep in mind that there are several different compression methods, and that the one that people usually refer to as 'zip' refers to PKZip, which is compatible with WinZip and InfoZip.
gzip and PKZip/WinZip/InfoZip use very different compression methods (just to say one difference, gzip can compress only one file, while the others can create compressed archives of several files), so compression and decompression programs will have to be paired. For example, gzip on one end and Compress::Zlib on the other.
--
dakkar - Mobilis in mobile
Most of my code is tested...
--
tbone1, YAPS (Yet Another Perl Schlub)
And remember, if he succeeds, so what.
- Chick McGee
use Compress::Zlib;
my $fil = shift || die ("need compressed file, stopped");
die "$fil not a gz'd file, stopped"
unless (($fil =~ /.gz$/) || ($fil =~ /.Z$/));
(my $rootfil = $fil) =~ s/.gz$//;
open OOTFIL, ">$rootfil" or die ("cannot open file for gunzip");
binmode OOTFIL or die ("cannot binmode $rootfil");
$gz = gzopen($fil, "rb") or die ("can't open $fil, $gzerrno, stopped");
my $buffer;
print OOTFIL $buffer while $gz->gzread($buffer) > 0;
die "Error reading from file $file: $gzerrno\n" if $gzerrno != Z_STREAM_END;
$gz->gzclose();
close(OOTFIL);
hasta la vista
Just to go completely the other direction, you could also ZIP (rather than compress) the test files on the Unix box. The lazy way would be to use the 'jar' utility (if java is installed).
$ jar cf result.zip file1.txt file2.txt ...
The perlish way would be to use a utility like the following to make the zip file ...
my $zipfile = shift @ARGV;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
my $zip = Archive::Zip->new();
my $member = $zip->addFile( @ARGV );
die 'write error'
unless $zip->writeToFileNamed( $zipfile ) == AZ_OK;
Get yourself [http://unxutils.sourceforge.net/|UnixUtils] and use its compress.exe and a forked [open].
perl -e"open IN, 'compress.exe -dc file.z |' or die $!; my @data ="
perlmonks.org content © perlmonks.org and BrowserUk, dakkar, iburrell, idsfa, nimdokk, spikey_wan, tbone1, wufnik, zentara
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03