使用DotNetZIP无法压缩超过10 GB的大文件

时间:2017-06-21 09:51:17

标签: c# dotnetzip

我能够压缩最多1 GB的文件夹,但我必须压缩超过10 GB。

 string filePath  = C:\Work; // path of the source file 
 private void compressFile(string filePath)
 {
     using (ZipFile zip = new ZipFile())
     {                    
        zip.AddDirectory(Path.Combine(filePath, "Demo"));
        if (File.Exists(Path.Combine(filePath, "Demo.zip")))
        {
           File.Delete(Path.Combine(filePath, "Demo.zip"));
           zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;                
           zip.Save(Path.Combine(filePath, "Demo.zip"));                        
         }   

         zip.Save(Path.Combine(filePath, "Demo.zip"));               
       }      
    }

1 个答案:

答案 0 :(得分:5)

我假设这里的问题是内存不足,因为在zip.Save调用之前所有内容都在内存中。

建议:不要使用DotNetZIP。如果您改为使用System.IO.Compression.ZipArchive,则启动,为其提供输出流(在构造函数中)。将它设为FileStream并且您应该设置它,而不需要首先缓冲内存中的所有内容。

您需要使用ZipArchiveMode.Create

相关问题