DotNetZip How to fix 0000000 CRC32 issue?

戏子无情 提交于 2019-12-25 02:42:20

问题


I'm using DotNetZip to add multiple MemoryStreams to a single archive. So far, my code works when I select 1 or 2 files, but does not work if I add more. I found the difference is the CRC32 are all 00000000 for those bad archive. Is it something about the archive size? Any help is appreciated! My code in C#:

foreach(.....){
       var zipEntryName=.....//Get the file name in string;
       var UDocument = .....//Get a object
       var UStream = UDocument .GetStream();
       UStream.Seek(0, SeekOrigin.Begin);
       ZipEntry entry = zipFile.AddEntry(zipEntryName,UStream );
 }
 var outputStream = new MemoryStream();
            outputStream.Seek(0, SeekOrigin.Begin);
            zipFile.Save(outputStream);
            outputStream.Flush();
            return outputStream;

回答1:


I think its beacuse of memory leakage. you are creating object in foreach loop and here the problem comes if the loop iterates more times.

here the problem comes in your code:

var UDocument = .....//Get a object

a singleton is a class that can be instantiated once, and only once. use singleton class as below:

public static SingletonSample InstanceCreation()
{
    private static object lockingObject = new object();
    if(singletonObject == null)
    {
         lock (lockingObject)
         {
             singletonObject = new SingletonSample();

         }
    }
    return singletonObject;
}


来源:https://stackoverflow.com/questions/19730893/dotnetzip-how-to-fix-0000000-crc32-issue

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