GZipStream 4G 限制 - 总计或当前流式传输?

发布于 2024-11-27 00:18:26 字数 1292 浏览 1 评论 0原文

让一个 GzipStream 提供一个 SSLStream

今天第一次注意到 “gzip 流不能包含超过 4GB 的数据。”

at System.IO.Compression.FastEncoder.GetCompressedOutput(Byte[] outputBuffer)
at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
at System.IO.Compression.DeflateStream.Write(Byte[] array, Int32 offset, Int32 count)
at System.IO.Compression.GZipStream.Write(Byte[] array, Int32 offset, Int32 count)
at ...

网络写入器输入数据的速度比读取器获取数据的速度快。因此,我不清楚错误的原因。

这是对通过流写入的总字节数的限制,还是将数据从 GZipStram 中取出并放入 SSLStream 时积压的问题?

Reader 能够在流结束之前解压缩并使用数据,因此我从未想过写入的总字节数可能有这样的限制。

似乎没有办法检查长度。

有人可以分享他们如何处理这个问题的示例吗?

代码大纲:

TcpClient network = = new TcpClient();
network.Connect(m_config.Address.Host, m_config.Address.Port);
SslStream sslStream = new SslStream(network.GetStream(), true .. ssl bits
Stream outStream = new GZipStream(sslStream, CompressionMode.Compress, true);

try {
    String nextMessage;
    while (messages.Dequeue(out nextMessage))
    {
        byte[] buffer = Encoding.UTF8.GetBytes(nextMessage + "\n");

        outStream.Write(buffer, 0, buffer.Length);
    }
} catch()

Have aa GzipStream feeding an SSLStream.

First time today noticed
"The gzip stream can't contain more than 4GB data."

at System.IO.Compression.FastEncoder.GetCompressedOutput(Byte[] outputBuffer)
at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
at System.IO.Compression.DeflateStream.Write(Byte[] array, Int32 offset, Int32 count)
at System.IO.Compression.GZipStream.Write(Byte[] array, Int32 offset, Int32 count)
at ...

The Writer to the network is feeding in data faster than the Reader is getting the data. As such the cause of the error is unclear to me.

Is this is a limitation on the total bytes written through the stream or is this is an issue with backlog getting the data out of the GZipStram and into the SSLStream?

The Reader is able to unzip and use the data before the stream ends, so I never thought that there might be such a limit on total bytes written.

There doesn't seem to be a way to check the length.

Could anybody share examples on how they handled this?

Code outline:

TcpClient network = = new TcpClient();
network.Connect(m_config.Address.Host, m_config.Address.Port);
SslStream sslStream = new SslStream(network.GetStream(), true .. ssl bits
Stream outStream = new GZipStream(sslStream, CompressionMode.Compress, true);

try {
    String nextMessage;
    while (messages.Dequeue(out nextMessage))
    {
        byte[] buffer = Encoding.UTF8.GetBytes(nextMessage + "\n");

        outStream.Write(buffer, 0, buffer.Length);
    }
} catch()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月蹉跎了容颜 2024-12-04 00:18:26

.NET Framework 2.0/3.0/3.5 中的 GZipStream 和 DeflateStream 类不支持读取/写入总计超过 4 GB 的数据。

.NET Framework 4.0 中已删除此限制。

The GZipStream and DeflateStream classes in .NET Framework 2.0/3.0/3.5 do not support reading/writing more than a total of 4 GB of data.

This limitation has been removed in .NET Framework 4.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文