我可以压缩多达1GB的文件夹,但我必须压缩超过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"));
}
}
发布于 2017-06-21 09:55:45
我假设这里的问题是内存不足,因为在zip.Save
调用之前,所有的东西都在内存中。
建议:不要使用DotNetZIP
。如果您使用System.IO.Compression.ZipArchive
,那么首先给它一个输出流(在构造函数中)。将其设置为FileStream
,而不需要首先缓冲内存中的所有内容。
您需要使用ZipArchiveMode.Create
https://stackoverflow.com/questions/44672682
复制相似问题