[英]Zipping huge amount of files ( zip outcome over 1GB )
I've wrote a small app that compresses files and deletes them using DotNetZip,我写了一个小应用程序,它使用 DotNetZip 压缩文件并删除它们,
it achieved compressing files to 1.4 GB zips它实现了将文件压缩到 1.4 GB 的 zips
probably zips larger then this it's crashing可能拉链更大,然后它崩溃了
here is the stacktrace I got:这是我得到的堆栈跟踪:
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
here is the compression code, I tried to split it to 1GB Zip files这是压缩代码,我尝试将其拆分为 1GB Zip 文件
line 78 is the one call the function below第 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);
}
}
issue solved问题已解决
apparently I was missing a configuration显然我缺少一个配置
after adding添加后
zip.UseZip64WhenSaving = Zip64Option.Always;
changing the function to the below:将函数更改为以下内容:
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);
}
}
it solved the zipping它解决了压缩问题
thanks for the useful comments感谢有用的评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.