Greg Hewgill ([info]ghewgill) wrote,
@ 2007-08-23 21:22:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
how to decompress gzip stream with zlib

I'm posting this in my journal because it trips me up every time I have to do this, and I need something googleable so I can easily find this info next time.

To decompress a gzip format file with zlib, call inflateInit2 with the windowBits parameter as 16+MAX_WBITS, like this:

inflateInit2(&stream, 16+MAX_WBITS);

If you don't do this, zlib will complain about a bad stream format. By default, zlib creates streams with a zlib header, and on inflate does not recognise the different gzip header unless you tell it so. Although this is documented starting in version 1.2.1 of the zlib.h header file, it is not in the zlib manual.



(Post a new comment)


[info]taral
2007-09-04 01:54 am UTC (link)
...

OMG.

(Reply to this)

Thanks for that...
(Anonymous)
2009-01-07 07:07 am UTC (link)
Thanks for that tip. i haven't seen it referenced anywhere else, but there's an indirect reference to it here:

http://zlib.net/zlib_faq.html#faq20

The question is "Well that's nice, but how do I make a gzip file in memory?", in case the numbering doesn't line up by the time that link is clicked.

(Reply to this)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…