zlib inflate CHUNK size has to be the same as the size used in deflation?

泄露秘密 提交于 2020-01-07 04:03:05

问题


I followed the zlib inflate example from http://zlib.net/zlib_how.html to decompress a zipped file. Even after I defined the CHUNK size as 256KB, I see the output data of each inflate() function call is only 8KB. I knew the zipped file was deflated by using a CHUNK size of 8K, so does this mean zlib inflate's CHUNK size has to be the same as the size used in deflation?

If yes, without changing the source file, is there anyway to speed up decompression? Using a CHUNK size of 8K to decompress is slow.


回答1:


No, the chunk sizes do not have to be the same. A valid deflate stream can be decoded by inflate using any chunk size.

Even after I defined the CHUNK size as 256KB, I see the output data of each inflate() function call is only 8KB.

From the discussion in the comments, you do not have a single deflate stream but rather a concatenation of a sequence of small deflate streams. Do inflate that, you will need to simply restart the inflate process each time you complete a stream, which is indicated by Z_STREAM_END being returned by inflate(). Use inflateReset() instead of inflateEnd() followed by inflateInit(), since that saves time and avoids unnecessary frees and allocations of memory.

There is no way to speed up the decompression beyond that.



来源:https://stackoverflow.com/questions/17051445/zlib-inflate-chunk-size-has-to-be-the-same-as-the-size-used-in-deflation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!