ICSharpCode.SharpZipLib.Zip crc32

天大地大妈咪最大 提交于 2019-12-10 23:53:41

问题


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?


回答1:


I'd take a guess, you should call:

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

Just before you invoke df.GetBuffer()




回答2:


Try to explicitly flush the stream "s" before close.



来源:https://stackoverflow.com/questions/5461207/icsharpcode-sharpziplib-zip-crc32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!