ICSharpCode.SharpZipLib.Zip crc32
我正在使用 ICSharpCode.SharpZipLib.Zip 来压缩文件和文件夹,并使用 response.Binary write 将其作为内存流传递。
这是我的代码:
MemoryStream df= new MemoryStream();
ZipOutputStream s = new ZipOutputStream(df);
s.SetLevel(9);
byte[] data = (byte[])file.OpenBinary();
s.Write(data, 0, data.Length);
s.Finish();
s.Close();
byte[] outBuf = df.GetBuffer();
Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader("content-disposition", "inline; filename="out.zip");
Response.ContentType = "application/zip";
Response.BinaryWrite(outBuf);
HttpContext.Current.ApplicationInstance.CompleteRequest();
当我尝试打开 out.zip 文件时,提示 zip 文件已损坏或 损坏了,crc值显示为000000,
如何解决? 为什么会出现这个错误?
I am using ICSharpCode.SharpZipLib.Zip to compress the files and folders and pass it as memorystream using response.Binary write.
Here is my code:
MemoryStream df= new MemoryStream();
ZipOutputStream s = new ZipOutputStream(df);
s.SetLevel(9);
byte[] data = (byte[])file.OpenBinary();
s.Write(data, 0, data.Length);
s.Finish();
s.Close();
byte[] outBuf = df.GetBuffer();
Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader("content-disposition", "inline; filename="out.zip");
Response.ContentType = "application/zip";
Response.BinaryWrite(outBuf);
HttpContext.Current.ApplicationInstance.CompleteRequest();
When I try to open the out.zip file, it is saying that the zip file is either corrupted or
damaged, and the crc value is showing as 000000.
What is the solution for this?
Why is this error is occurring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜测,您应该调用:
在调用 df.GetBuffer() 之前调用
I'd take a guess, you should call:
Just before you invoke
df.GetBuffer()
尝试在关闭之前显式刷新流“s”。
Try to explicitly flush the stream "s" before close.