当压缩文件达到 65536 字节时,Ionic.zlib 停止压缩? - C#
嘿,我在使用 Ionic.zlib 压缩文件时遇到问题,我对 C# 很陌生,所以问题可能很容易解决。如果我压缩一个大文件,假设大小为 500kb,那么一旦压缩文件达到 65536 字节,它就会停止,如果我随后解压缩该文件,则会丢失大量数据:/。我可以通过将缓冲区设置为 4,000,000 来解决此问题,但我听说最好将其设置为 0x4000。
ZlibStream compressor = new ZlibStream(gsc_stream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
byte[] buffer = new byte[0x4000];
Int32 n;
int previous = Convert.ToInt32(zone.Position);
while ((n = compressor.Read(buffer, 0, buffer.Length)) != 0)
{
zone.Write(buffer, 0, n);
}
zone.Flush();
compressor.Flush();
Hey, I'm having problems compressing files with Ionic.zlib, I'm very new to C# so the problem may be easily solvable. If I compress a large file, let's say 500kb in size then once the compressed file has reached 65536 bytes it will stop, if I then decompress the file theres a lot of data missing :/. I can fix this by setting the buffer to like 4,000,000, but I heard that it's best to have it set to 0x4000.
ZlibStream compressor = new ZlibStream(gsc_stream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
byte[] buffer = new byte[0x4000];
Int32 n;
int previous = Convert.ToInt32(zone.Position);
while ((n = compressor.Read(buffer, 0, buffer.Length)) != 0)
{
zone.Write(buffer, 0, n);
}
zone.Flush();
compressor.Flush();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你的想法正好相反。
如果您尝试压缩流
gsc_stream
中的文件并将结果写入流zone
,那么正确的代码是:Looks like you have it the other way around.
If you're trying to compress the file in the stream
gsc_stream
and write the result into the streamzone
then correct code would be: