For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2005 > compress utility != Compress::Zlib::compress() on linux and Windows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author compress utility != Compress::Zlib::compress() on linux and Windows
john_ramsden@sagitta-ps.com

2005-03-30, 3:57 pm


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.


Cheers

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);

return;
}

#----------------------------------------------

# 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);

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com