| |
 |
|
|
Science Forum Index » Compression Forum » Retrieving the trailers from a zipped stream...
Page 1 of 1
|
| Author |
Message |
| ... |
Posted: Wed May 07, 2008 4:14 am |
|
|
|
Guest
|
Hi, am new to zipping.Am currently receiving , a stream of zipped data
from servers and unzipping it accordingly based on whether its gzip,
raw deflate or zlib. However,am working with a memory constraint.When
calling the ZlibUncompress function ( int ZEXPORT ZlibUnCompress
( BYTE FAR *dest, ULONG FAR *destLen, const BYTE FAR *source, ULONG
sourceLen) ) in ZlibUncompr.c we need to pass the destination
buffer.For this we need to have an idea of the length of the
uncompressed data.I read in the specs that the length of the
uncompressed data is stored in the trailer of the zipped incoming
stream.Since am working with very less memory,i would need to know the
exact length of the uncompressed data, so as to not allocate more than
reqd.Can somebody plz tell me how to extract it from the trailer of
the zipped stream or are there any Api's in the zlib library through
which i can do the needful??Please help.
Thank you. |
|
|
| Back to top |
|
| Mark Adler... |
Posted: Wed May 07, 2008 7:34 am |
|
|
|
Guest
|
On May 7, 7:14 am, rohitpshe... at (no spam) gmail.com wrote:
Quote: Am currently receiving , a stream of zipped data
from servers and unzipping it accordingly based on whether its gzip,
raw deflate or zlib.
...
Since am working with very less memory,i would need to know the
exact length of the uncompressed data, so as to not allocate more than
reqd.Can somebody plz tell me how to extract it from the trailer of
the zipped stream or are there any Api's in the zlib library through
which i can do the needful??
Of the gzip, zlib, and raw deflate formats, only gzip puts the
uncompressed length in the stream. For gzip , the last four bytes is
the length of the uncompressed data in little-endian order. However
there are significant caveats on that. First, since it is four bytes,
it is actually the length modulo 2^32, for those cases where the
uncompressed length is >= 4 GB. Second, a gzip stream may consist of
multiple gzip streams, in which case the last four bytes only gives
you the length of the last piece. Third, some gzip streams have junk
on the end, in which case you'll get something other than the length
in the last four bytes.
So not only can you not find the uncompressed length for zlib and raw
deflate, you also cannot find it reliably for gzip.
I recommend that you not use approaches that require that you know the
length. zlib provides the inflateInit2(), inflate(), and
inflateReset(), and inflateEnd() functions that allow you to
decompress in pieces, with repeated uses of inflate(). You should use
those. Read the documentation in zlib.h.
Mark |
|
|
| Back to top |
|
| |
|
Page 1 of 1
All times are GMT - 5 Hours
The time now is Tue Jul 08, 2008 10:08 pm
|
|