zlib inflate CHUNK 大小必须与放气中使用的大小相同吗? [英] zlib inflate CHUNK size has to be the same as the size used in deflation?

查看:33
本文介绍了zlib inflate CHUNK 大小必须与放气中使用的大小相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 http://zlib.net/zlib_how.html 中的 zlib inflate 示例进行解压缩一个压缩文件.即使在我将 CHUNK 大小定义为 256KB 之后,我看到每个 inflate() 函数调用的输出数据也只有 8KB.我知道压缩文件是通过使用 8K 的 CHUNK 大小进行压缩的,那么这是否意味着 zlib inflate 的 CHUNK 大小必须与 deflation 中使用的大小相同?

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?

如果是,不改变源文件,有没有办法加速解压?使用大小为 8K 的 CHUNK 来解压很慢.

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

推荐答案

不需要,块大小不必相同.可以通过使用任何块大小的 inflate 来解码有效的 deflate 流.

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

即使在我将 CHUNK 大小定义为 256KB 之后,我也看到了每个 inflate() 函数调用只有 8KB.

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

根据评论中的讨论,您没有单个 deflate 流,而是一系列小 deflate 流的串联.做膨胀,你需要在每次完成一个流时简单地重新启动膨胀过程,这由 inflate() 返回的 Z_STREAM_END 指示.使用 inflateReset() 而不是 inflateEnd() 后跟 inflateInit(),因为这样可以节省时间并避免不必要的内存释放和分配.

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.

这篇关于zlib inflate CHUNK 大小必须与放气中使用的大小相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆