我正在使用 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。
解决这个问题的方法是什么? 为什么会出现此错误?
最佳答案
我猜,你应该调用:
s.Flush();
df.Flush();
就在您调用 df.GetBuffer()
之前
关于c# - ICSharpCode.SharpZipLib.Zip crc32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5461207/