Compress::Zlib inflateInit help



Greetings.

I'm using Compress::Zlib for the first time. I'm working with strings
are are ZLib-compressed but not fully RFC1950 compliant. I'm getting
some errors and, although I have it working, I know there has to be
a better way.

I started pretty simple:

my ($inflate,$status);
($inflate,$status) = inflateInit();
while ($i<3)
{
print "$i\n";
# the strings are coming from an internet socket.
# i can probably get some sample lines if needed
read($socket,$line,$number);
($newline,$status) = $inflate->inflate($line);
print "line -> $newline\n";
print "status -> $status\n";
print "msg -> " , $inflate->msg() , "\n";
$i++;
}

and got these results

0
line ->
status -> data error
msg -> incorrect header check
1
line ->
status -> data error
msg -> incorrect header check
2
line ->
status -> data error
msg -> incorrect header check

So I did some research and found about adding the header to the string:

my ($inflate,$status);
($inflate,$status) = inflateInit();
while ($i<3)
{
print "$i\n";
# the strings are coming from an internet socket.
# i can probably get some sample lines if needed
read($socket,$line,$number);
$line = "\x78\x01$line"; # i added this line here
($newline,$status) = $inflate->inflate($line);
print "line -> $newline\n";
print "status -> $status\n";
print "msg -> " , $inflate->msg() , "\n";
$i++;
}

and did a little better

0
line -> 06710002515770TradePAC USD17393883907^PDP.IV
status ->
msg ->
1
line ->
status -> data error
msg -> incorrect data check
2
line ->
status -> data error
msg -> incorrect data check

So I adjusted the header thusly

my ($inflate,$status);
($inflate,$status) = inflateInit();
while ($i<3)
{
print "$i\n";
# the strings are coming from an internet socket.
# i can probably get some sample lines if needed
read($socket,$line,$number);
$line = "\x78\x01$line" if $i==0; # i altered this line here
($newline,$status) = $inflate->inflate($line);
print "line -> $newline\n";
print "status -> $status\n";
print "msg -> " , $inflate->msg() , "\n";
$i++;
}

but same results

line -> 06710002515770TradePAC USD17393883907^PDP.IV
status ->
msg ->
1
line ->
status -> data error
msg -> incorrect data check
2
line ->
status -> data error
msg -> incorrect data check

Now, here is what I finally got working:

while ($i<3)
{
print "$i\n";
my ($inflate,$status);
($inflate,$status) = inflateInit(); # moved inflateInit here
# the strings are coming from an internet socket.
# i can probably get some sample lines if needed
read($socket,$line,$number);
$line = "\x78\x01$line"; # always add header
($newline,$status) = $inflate->inflate($line);
print "line -> $newline\n";
print "status -> $status\n";
print "msg -> " , $inflate->msg() , "\n";
$i++;
}

but it has to be inefficient always running inflateInit.

So can somebody help me figure out what I'm doing wrong?

Thanks.

--hymie! http://lactose.homelinux.net/~hymie hymie@xxxxxxxxxxxxxxxxxxxxx
------------------------ Without caffeine for 546 days ------------------------
Convicted of a crime I didn't even commit! Attempted Murder -- now, honestly,
what is that? Do they give a Nobel Prize for Attempted Chemistry? Do they?
-- Sideshow Bob (The Simpsons)
-------------------------------------------------------------------------------
.



Relevant Pages

  • Re: Compress::Zlib inflateInit help
    ... I'm working with strings ... # the strings are coming from an internet socket. ... status -> data error ... msg -> incorrect header check ...
    (comp.lang.perl.misc)
  • 8007045D
    ... when i play a video i get a msg that says "data error: cyclic redundancy check" ...
    (microsoft.public.windowsmedia.player)