Click here to get back home

Compress::Zlib unable to inflate

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Compress::Zlib unable to inflate cobbletang 07-24-2006
Get Chitika Premium
Posted by cobbletang on July 24, 2006, 3:52 am
Please log in for more thread options


Hi all,

I gave myself a headache trying to figure this one out. Any help would
be much appreciated. Just trying to understand how the Compress
module's inflate and deflate functions work. My understanding is
calling deflate on an input stream (a string for example) will compress
the stream resulting in a binary representation, and then calling
inflate on that same stream should restore the original stream.

To test this theory I tried to follow the examples in the docs.
Deflate seems to work properly, converting my test string into a
unintelligble stream of binary data. When I try to inflate the stream
back, I get error message -3 and the zlib msg() returns 'unknown
compression method'.

Using activestate perl on windows XP.

code as follows:

use strict;
use Compress::Zlib;

my ($out, $status, $nout);
my $x = deflateInit() or die "Cannot init deflation stream\n";

my $testStream = "deflate this text please\n";
($out,$status) = $x->deflate($testStream);

$status == Z_OK or die "deflation failed\n";
($out, $status) = $x->flush();

$status == Z_OK or die "deflation failed\n";
print "[$out]\n";

my ($y, $status) = inflateInit() or die "Cannot init inflation
stream\n";
if ($y == undef) {print "inflateInit failed with error code:
$status\n";}

($nout, $status) = $y->inflate($out);
if ($nout == undef) {print "Error inflating: errnum: $status\n";}

print "bytes in: " . $y->total_in() . " [$nout]\n";
$status == Z_OK or die "inflation failed: ". $y->msg() . "\n";

----------------
output is:

<string of binary characters>
Error inflating: errnum: -3
bytes in: 1 []
inflation failed: unknown compression method

I'm at a loss. Any help would be greatly appreciated. Thanks.

JJ


Posted by Paul Marquess on July 24, 2006, 4:01 am
Please log in for more thread options



> Hi all,
>
> I gave myself a headache trying to figure this one out. Any help would
> be much appreciated. Just trying to understand how the Compress
> module's inflate and deflate functions work. My understanding is
> calling deflate on an input stream (a string for example) will compress
> the stream resulting in a binary representation, and then calling
> inflate on that same stream should restore the original stream.
>
> To test this theory I tried to follow the examples in the docs.
> Deflate seems to work properly, converting my test string into a
> unintelligble stream of binary data. When I try to inflate the stream
> back, I get error message -3 and the zlib msg() returns 'unknown
> compression method'.
>
> Using activestate perl on windows XP.
>
> code as follows:
>
> use strict;
> use Compress::Zlib;
>
> my ($out, $status, $nout);
> my $x = deflateInit() or die "Cannot init deflation stream\n";
>
> my $testStream = "deflate this text please\n";
> ($out,$status) = $x->deflate($testStream);
>
> $status == Z_OK or die "deflation failed\n";
> ($out, $status) = $x->flush();

You are overwriting $out in the flush call. Try this instead

($out1, $status) = $x->flush();
$out .= $out1 ;


> $status == Z_OK or die "deflation failed\n";
> print "[$out]\n";
>
> my ($y, $status) = inflateInit() or die "Cannot init inflation
> stream\n";
> if ($y == undef) {print "inflateInit failed with error code:
> $status\n";}
>
> ($nout, $status) = $y->inflate($out);
> if ($nout == undef) {print "Error inflating: errnum: $status\n";}
>
> print "bytes in: " . $y->total_in() . " [$nout]\n";
> $status == Z_OK or die "inflation failed: ". $y->msg() . "\n";
>


Paul



Posted by cobbletang on July 24, 2006, 2:05 pm
Please log in for more thread options


Paul Marquess wrote:
> > Hi all,
> >
> > I gave myself a headache trying to figure this one out. Any help would
> > be much appreciated. Just trying to understand how the Compress
> > module's inflate and deflate functions work. My understanding is
> > calling deflate on an input stream (a string for example) will compress
> > the stream resulting in a binary representation, and then calling
> > inflate on that same stream should restore the original stream.
> >
> > To test this theory I tried to follow the examples in the docs.
> > Deflate seems to work properly, converting my test string into a
> > unintelligble stream of binary data. When I try to inflate the stream
> > back, I get error message -3 and the zlib msg() returns 'unknown
> > compression method'.
> >
> > Using activestate perl on windows XP.
> >
> > code as follows:
> >
> > use strict;
> > use Compress::Zlib;
> >
> > my ($out, $status, $nout);
> > my $x = deflateInit() or die "Cannot init deflation stream\n";
> >
> > my $testStream = "Cannot init deflation stream\n";
> > ($out,$status) = $x->deflate($testStream);
> >
> > $status == Z_OK or die "deflation failed\n";
> > ($out, $status) = $x->flush();
>
> You are overwriting $out in the flush call. Try this instead
>
> ($out1, $status) = $x->flush();
> $out .= $out1 ;
>
>
> > $status == Z_OK or die "deflation failed\n";
> > print "[$out]\n";
> >
> > my ($y, $status) = inflateInit() or die "Cannot init inflation
> > stream\n";
> > if ($y == undef) {print "inflateInit failed with error code:
> > $status\n";}
> >
> > ($nout, $status) = $y->inflate($out);
> > if ($nout == undef) {print "Error inflating: errnum: $status\n";}
> >
> > print "bytes in: " . $y->total_in() . " [$nout]\n";
> > $status == Z_OK or die "inflation failed: ". $y->msg() . "\n";
> >
>
>
> Paul

Thanks Paul,

That did the trick. I fixed the expressions with undef in them as
well. Here is working code.

use strict;
use Compress::Zlib;


#------ deflate -------
my ($out, $out1, $status, $nout);
my $x = deflateInit() or die "this text has been deflated/inflated";

my $testStream = "deflate this text please";
($out,$status) = $x->deflate($testStream);

$status == Z_OK or die "deflation failed\n";
($out1, $status) = $x->flush();

$out .= $out1;

$status == Z_OK or die "deflation failed\n";
print "deflated output: [$out]\n";


#------ inflate -------

my ($y, $status) = inflateInit() or die "Cannot init inflation
stream\n";
if (!defined($y)) {print "inflateInit failed with error code:
$status\n";}

($nout, $status) = $y->inflate($out);
if (!defined($nout)) {print "Error inflating: errnum: $status\n";}

print "inflated output: [$nout]\n";
$status == Z_OK or $status == Z_STREAM_END or die "inflation failed: ".
$y->msg() . "\n";

_________
output:
deflated output: [non-ascii characters]
inflated output: [this text has been deflated/inflated]

Thanks again Paul!

JJ


Similar ThreadsPosted
Compress::Zlib installation August 12, 2006, 7:25 am
Error handling with Compress::Zlib October 21, 2004, 12:26 pm
Need help with Compress::Zlib code (inflation gives error) November 17, 2005, 6:23 pm
ANNOUNCEMENT: Compress::Bzip2 2.08 May 11, 2005, 11:26 pm
Compress::Bzip2 needs work April 20, 2005, 9:41 pm
ANNOUNCEMENT: Compress::Bzip2 2.08 July 9, 2007, 3:51 pm
Proposed Module: Compress::AsciiFlate March 10, 2006, 6:37 am
Unable to connect a website using LWP February 23, 2006, 4:31 am
Unable to load module March 16, 2006, 12:00 am
Perl unable to find modules August 12, 2004, 12:58 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap