unzipping unix files on windows
spikey_wan
created: 2004-07-02 06:25:10
Hello World!,

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.

Re: unzipping unix files on windows
created: 2004-07-02 08:12:51
.Z files are NOT zip files, they are made with compress. Read "man compress". You probably want the Compress::Zlib module.

I'm not really a human, but I play one on earth. flash japh
Re: unzipping unix files on windows
created: 2004-07-02 08:20:34
As zentara indicates, these are not Zip files, and cannot be unzipped (unless you happen to be using WinZip). The options would be to use the module mentioned (Compress::Zlib) or zip the files using a true zip program (such as 'gzip').
Re^2: unzipping unix files on windows
created: 2004-07-02 08:55:08

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...

Perl is strongly typed, it just has very few types (Dan)

Re^3: unzipping unix files on windows
created: 2004-07-02 10:23:15
Actually, I believe that gzip can uncompress .Z files but it cannot compress files into .Z format for licensing reasons or some such. So you may be good to go with that.

--
tbone1, YAPS (Yet Another Perl Schlub)
And remember, if he succeeds, so what.
- Chick McGee

Re^3: unzipping unix files on windows
created: 2004-07-02 12:22:06
Actually, zip and gzip use the same compression algorithm, deflate. Deflate is a variant of LZ77, and is used in other file formats (PNG, PDF). The file formats are different, with gzip compressing a single file, and zip making an archive with multiple files.
Re: unzipping unix files on windows
created: 2004-07-02 10:15:21
here is one way to do it. tested for .gz files. should also work for .Z files.

source: adapted from the compress::zlib example code.


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
...wufnik

-- in the world of the mules there are no rules --
Re^2: unzipping unix files on windows
created: 2004-07-05 09:48:44
Thanks for your help.

Unfortunately, when I tried your code, it wouldn't do a .Z file. I get "Error reading from file...".

Re: unzipping unix files on windows
created: 2004-07-02 15:17:37

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;

If anyone needs me I'll be in the Angry Dome.
Re: unzipping unix files on windows
created: 2004-07-02 17:08:38

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 = "

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - [Abigail-II|Abigail]
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - [tachyon]

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