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

Dut*_*t93 -1 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"));               
       }      
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 5

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

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

你需要使用 ZipArchiveMode.Create