压缩大量文件(压缩结果超过1GB)

时间:2017-03-16 20:16:46

标签: c# dotnetzip


我写了一个小应用程序压缩文件并使用DotNetZip删除它们,
它实现了将文件压缩到1.4 GB的拉链 可能拉链大一点然后它崩溃了

这是我得到的堆栈跟踪:

   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at CustomFileCompressor.Program.ParallelCompress(List`1 relevantFiles, Int32
zipYear, Int32 zipMonth, String outputFile) in d:\C#\CustomFileCompressor\Custom
FileCompressor\CustomFileCompressor\Program.cs:line 135
   at CustomFileCompressor.Program.Main(String[] args) in d:\C#\CustomFileCompre
ssor\CustomFileCompressor\CustomFileCompressor\Program.cs:line 78

这里是压缩代码,我试图将其拆分为1GB Zip文件
第78行是调用下面的函数

line 78:   ParallelCompress(FilesInMonth, zipYear, zipMonth, outFile);


static void  ParallelCompress(List<FileInfo> relevantFiles, int zipYear, int zipMonth, string outputFile)
    {
        List<string> filesToZip = relevantFiles.Select(fi => fi.FullName).ToList();
        using (ZipFile zip = new ZipFile())
        {
            string outputfile = string.Format(outputFile, zipYear, zipMonth);
            zip.MaxOutputSegmentSize = 1024 * 1024;
            zip.AddFiles(filesToZip, true, "");

            zip.Save(outputfile);
        }
    }

1 个答案:

答案 0 :(得分:0)

问题解决了 显然我错过了一个配置 添加后

zip.UseZip64WhenSaving = Zip64Option.Always;

将功能更改为以下内容:

static void  ParallelCompress(List<FileInfo> relevantFiles, int zipYear, int zipMonth, string outputFile)
    {
        List<string> filesToZip = relevantFiles.Select(fi => fi.FullName).ToList();
        using (ZipFile zip = new ZipFile())
        {
            string outputfile = string.Format(outputFile, zipYear, zipMonth);
            zip.ParallelDeflateThreshold = 0;
            zip.UseZip64WhenSaving = Zip64Option.Always;
            zip.MaxOutputSegmentSize = 1024 * 1024 * 1024;
            zip.AddFiles(filesToZip, true, "");

            zip.Save(outputfile);
        }
    }
它解决了拉链的问题 感谢有用的评论