Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"incorrect header check" using ZLIB Compression

2,591 views
Skip to first unread message

Kevin Kalbfleisch

unread,
Mar 22, 2002, 12:26:32 PM3/22/02
to
I have written a simple compression program which uses ZLIB 1.1.4 to
compress a chunk of data in memory. I am using the ZLIB library as follows:

RWBoolean
ZLIBCompressionImpl::compress( const char* data_in,
unsigned int data_in_len,
char* data_out,
unsigned int* data_out_len )
{
int err = ::compress( (unsigned char *) data_out,
(unsigned long* ) data_out_len,
(unsigned char *) data_in,
(unsigned long) data_in_len );
if( err != Z_OK )
{
THROW_SEP( "ZLIB compression error" );
}

return TRUE;
}


Every thing works fine and a I can decompress the data using:

RWBoolean
ZLIBCompressionImpl::uncompress( const char* data_in,
unsigned int data_in_len,
char* data_out,
unsigned int* data_out_len )
{
int err = ::uncompress( (unsigned char *) data_out,
(unsigned long* ) data_out_len,
(unsigned char *) data_in,
(unsigned long) data_in_len );
if( err != Z_OK )
{
THROW_SEP( "ZLIB compression error" );
}

return TRUE;
}

As long as I am using the C++ code above I can compress and decompress at
will, and have never seen an error. The problem comes in when
I try to decompress the data in python.

If I write the compressed data to a file as follows:
ofstream oFile3;
oFile3.open( "rebundle.varz", ios:: out | ios::binary );
int compressedLen = compressed.length();
cout << "About to write: " << compressedLen
<< " bytes to rebundle.varz" << endl;
oFile3.write( (char*)&compressedLen , 4 );
oFile3.write( compressed.data(), compressedLen );
oFile3.flush();
oFile3.close();

then read it in with python and try to decompress it:

Python 2.1.1 (#1, Oct 9 2001, 13:27:21) [C] on aix4
Type "copyright", "credits" or "license" for more information.
>>>

fh = open( name, "rb" )
lenStr = fh.read( 4 )
length = struct.unpack( '!L', lenStr )[0]
blob = fh.read( length )
blob = zlib.decompress( blob )

I then get the following error:
zlib.error: Error -3 while decompressing data: incorrect header check.

Python is reading the correct number of bytes and the data looks the
same...

Is there some extra header that I should be writing? Does the python
version of ZLIB have known problems (I think that it is using ZLIB 1.1.3)

Any ideas?

Thanks,

Kevin Kalbfleisch
kev...@cosd.fedex.com


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
Check out our new Unlimited Server. No Download or Time Limits!
-----== Over 80,000 Newsgroups - 19 Different Servers! ==-----

Andreas Koltes

unread,
Mar 22, 2002, 5:24:26 PM3/22/02
to
If you are using 32 KB sliding window (default) the ZLib header should be:

0x78, 0xDA - max mode
0x78, 0x9C - normal mode
0x78, 0x5E - fast mode
0x78, 0x01 - no compression

If you use preset dictionaries the second header byte looks different. In
this case an extended header is required too.

0 new messages