Compress::Zlib unable to inflate

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Compress::Zlib unable to inflate

    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

    cobbletang@gmail.com Guest

  2. Similar Questions and Discussions

    1. #40189 [NEW]: endless loop in zlib.inflate stream filter
      From: cellog@php.net Operating system: kubuntu linux PHP version: 5CVS-2007-01-22 (CVS) PHP Bug Type: Zlib Related Bug...
    2. #34667 [Com]: Notice: Unknown: Unable to find the wrapper "compress.bzip2".....
      ID: 34667 Comment by: saulovallory at yahoo dot com Reported By: webmaster at 24-99-92-156 dot no-ip dot com Status: ...
    3. #36515 [Asn->Csd]: stream_filter_append with zlib inflate filter on http stream crashes
      ID: 36515 Updated by: pollita@php.net Reported By: mark at vectrex dot org dot uk -Status: Assigned +Status: ...
    4. Need help with Compress::Zlib code (inflation gives error)
      Inflation execution gives error status=0. I tried reading thru examples in the manpage and elsewhere but just couldn't find the problem. I tried...
    5. Error handling with Compress::Zlib
      I have a script that periodically copies a number of files from /proc to a zipped file using this library. It's been working fine for over a year...
  3. #2

    Default Re: Compress::Zlib unable to inflate


    <cobbletang@gmail.com> wrote in message
    news:1153727523.833481.109300@75g2000cwc.googlegro ups.com...
    > 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


    Paul Marquess Guest

  4. #3

    Default Re: Compress::Zlib unable to inflate

    Paul Marquess wrote:
    > <cobbletang@gmail.com> wrote in message
    > news:1153727523.833481.109300@75g2000cwc.googlegro ups.com...
    > > 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

    cobbletang@gmail.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139