【问题标题】:ICSharpCode.SharpZipLib.Zip crc32ICSharpCode.SharpZipLib.Zip crc32
【发布时间】:2011-03-28 15:21:56
【问题描述】:

我正在使用 ICSharpCode.SharpZipLib.Zip 压缩文件和文件夹,并使用 response.Binary 写入将其作为内存流传递。

这是我的代码:

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。

解决办法是什么? 为什么会出现这个错误?

【问题讨论】:

    标签: c# asp.net sharepoint sharpziplib


    【解决方案1】:

    我猜,你应该打电话:

    s.Flush();
    df.Flush();
    

    就在你调用df.GetBuffer()之前

    【讨论】:

    • +1 因为我之前遇到了 SharpZipLib 的问题,因为我在需要刷新时没有刷新。
    • df 是一个 MemoryStream,不需要刷新。 MemoryStream 使用空方法覆盖 Flush()。
    【解决方案2】:

    尝试在关闭之前显式刷新流“s”。

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 2020-04-03
      • 2020-03-27
      • 2015-03-18
      • 1970-01-01
      • 2014-12-13
      • 2012-03-06
      • 2010-12-03
      相关资源
      最近更新 更多