in reply to Decoding .z and .gz files

.Z files (uppercase) are compressed using a simple LZW algorithm. You can unpack them with Compress::LZW or Compress::LZF.

update: oops, it says in the documentation that Compress::LZW does not support .Z files..

use Compress::LZF ':compress'; my $file = shift; open my $fh, '<', $file or die "Cannot open $file for input: $!\n"; local $/ = undef; my $decompressed = decompress(<$fh>);

Update: hmmm, I don't actually have any .Z files around, so I made one, and the above code fails to decompress it, as does Compress::Zlib's uncompress function. Sigh.

Do you have a decompress binary lying around? Or you don't and you really have to do this in Perl? Because if you did, it would probably be much faster to pay the system call and let the binary do the decompression.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: Decoding .z and .gz files
by blackadder (Hermit) on Mar 26, 2007 at 12:15 UTC
    Hi

    its a small "z" not a Capital "Z"

    Still I Tried Compress::LZF as suggested however I got this error
    C:\Perl>perl z.pl -I c:/perl/bin compressed data corrupted (size mismatch) at z.pl line 9, <$fh> chunk +1.
    Thanks
    Blackadder

      Nevertheless, I suspect it's supposed to be a capital Z. I don't suppose you could paste in a hex dump of the first 256 characters or so... It may reveal that the compression isn't ".z" or ".Z" at all.

      UPDATE: Wow, just wow. A hex dump would look more like this:

      0000000: 4120 6865 7820 6475 6d70 2077 6f75 6c64 A hex dump would 0000010: 206c 6f6f 6b20 6d6f 7265 206c 696b 6520 look more like 0000020: 7468 6973 3a0a this:.

      Of course, your tools may differ from xxd.

      -Paul

        Hi Paul

        How do you mean " hex dump of the first 256 characters"! Where from? do you mean the output from running the Copmress::LZF based script? Well this returned
        compressed data corrupted (size mismatch) at z.pl line 5.
        And the output from running Archice::Zip or Compress::Zlib returned an output similar to what you get if you open a bin file using a text editer (lots of goobldi gook on the screen including lots beeps)! do you still want me to post this output? aNYWAY HERE IS THE OUTPUT
        CH3viƍ9bҰ(K0bSy2ɓ(S\ɲ˂6h P ͚0n +F 6jhy3 4ntɴӧP3N97yCG*S\$CF g]˶۷pI`… FŌ;~,f9aĸF .w3w3  7ex6gװRu Xqo.X,N N| 4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