浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

how to decompress gzip stream with zlib

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?

posted on 2013-03-31 13:18  lexus  阅读(424)  评论(0编辑  收藏  举报