compress utility != Compress::Zlib::compress() on linux and Windows

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

For some reason when the compress utility is used to
create a .Z file, the result is not recognized by the Compress::Zlib
uncompress() function (on either Linux
or Windows).

And it turns out that Compress::Zlib::compress() produces
a _different_ .Z file. Editing the two seems to show that
the contents are the same after a certain point and thus
the headers differ. DOH!

I am running with perl v5.8.6, in which Compress::Zlib
v1.33 is bundled. (v1.34 was released in 2005-01; but I
doubt if 1.33 is drastically out of date.)

Can anyone shed some light on this? If so, you'll be doing
better than the Compress::Zlib documentation and any other
reference I've found after two hours Googling!!

Appended is my test script, which I'm sure is sound.


John Ramsden

   use strict;
   use warnings;

   use Compress::Zlib qw(compress uncompress);


sub jr_read ($)
   my $x_name = shift;

   local ($/);

   open (my $fh, "< $x_name")
      or die "open ('< $x_name') failed: $!";

   binmode ($fh);

   my $contents = <$fh>;

   close ($fh);

   return $contents;


sub jr_write ($$)
   my ($x_name, $x_contents) = @_;

   local ($/);

   open (my $fh, "> $x_name")
      or die "open ('> $x_name') failed: $!";

   binmode ($fh);

   print $fh $x_contents;

   close ($fh);



#  my $arch_path = 'jr.tar.Z';

  # try a compress of a small text file

   my $contents = compress (jr_read ('ls.txt'));

   jr_write ('ls.txt.Z', $contents);

   $contents = uncompress (jr_read ('ls.txt.Z'));

   jr_write ('ls_hack.txt', $contents);

#    ls_hack.txt ends up identical to ls.txt, as expected.
# BUT - if ls.txt.Z is created by command "compress ls.txt"
#       then uncompress() call above fails!!

   exit (0);

Site Timeline