Greg Hewgill (ghewgill) wrote,
Greg Hewgill
ghewgill

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.

Update: I've added this as a question (and answer!) on Stack Overflow: How can I decompress a gzip stream with zlib?

Subscribe

  • islands of the world tour 2009

    Amy and I haven't been back to North America to see family since we got married in 2007. We've been talking for a while about taking a trip back,…

  • changing travel plans

    Things are suddenly moving fast. It looks like Amy and I are going to try to make it to Austin in time for SXSW (that means leaving Canada around…

  • photos from the usa southwest trip

    I've finished culling, sorting, and organizing the photos that I took during our trip. There are 339 photos, 132 of which are in the "60 mi Gallery"…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 6 comments