“同步刷新”对于 Zlib 放气
我需要一个 zlib deflate 压缩流。在我的实现中,我必须在整个会话中使用单个流。在此会话期间,小块数据将通过压缩流传递。每次传递一个块时,都必须立即以压缩形式发送。
我的第一次尝试是使用 DeflateStream,但是当我发送第一个块时,它的压缩数据不会出现,直到我关闭流。
阅读zlib刷新模式,似乎有一种特定的模式我需要。
- 我是否使用正确的类(DeflateStream)进行 zlib deflate 压缩?
- 如何启用“同步刷新”行为?
I need a zlib deflate compressed stream. In my implementation I must use a single stream over the entire session. during this session small chunks of data will be passed through the compressed stream. Everytime a chunk is passed it must be sent in compressed form immediately.
My first attempt was using DeflateStream but when I send the first chunk its compressed data wont appear until I close the stream.
Reading about zlib flush modes it appears as if there is one specific mode for what I need.
- Am I using the correct class(DeflateStream) for zlib deflate compression?
- How can I enable "sync flush" behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DotNetZip 项目有一个子模块 Zlib,其中包含自己的 DeflateStream 实现。
此实现还有另一个名为 FlushMode 的属性:
The DotNetZip project has a submodule Zlib that contain an implementation of DeflateStream of its own.
This implementation has another property named FlushMode:
它确实只在关闭时刷新。您每次都需要使用不同的 DeflateStream 实例,将 true 传递给 重载的构造函数告诉它不在关闭 DeflateStream 时关闭底层流。
It does indeed only flush upon close. You will need to use a different DeflateStream instance each time, passing true to the overloaded constructor telling it not to close the underlying stream when you close the DeflateStream.
要回答有关如何启用“同步刷新”行为的问题,您应该查看 zlib 源代码中的 zpipe.c 示例。
将第一行替换为如下所示的第二行
Deflate()
将在每次输出缓冲区已满时返回或者当输入缓冲区为空时同时附加到
压缩流 一个空的文字块,也称为
“同步刷新”,除了最后的
Z_FINISH
标志。To answer your question about how you could enable "sync flush" behavior, you should see the zpipe.c example in the zlib source code.
Replace the 1st line with the 2nd line shown below
Deflate()
will return each time the output buffer is fullor when the input buffer is empty meanwhile appending to the
compressed stream an empty literal block also called a
"sync flush" except at the end which is the
Z_FINISH
flag.