如何使用没有压缩的 SharpZipLib 将文件添加到 Zip 存档?
Google 上的示例似乎少得可怜。
最佳答案
您可以使用 ZipOutputStream
类的 SetLevel
方法将压缩级别设置为 0。
using (ZipOutputStream s = new ZipOutputStream(File.Create("test.zip")))
{
s.SetLevel(0); // 0 - store only to 9 - means best compression
string file = "test.txt";
byte[] contents = File.ReadAllBytes(file);
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
s.PutNextEntry(entry);
s.Write(contents, 0, contents.Length);
}
编辑:实际上,在查看文档后,有一个更简单的方法。
using (ZipFile z = ZipFile.Create("test.zip"))
{
z.BeginUpdate();
z.Add("test.txt", CompressionMethod.Stored);
z.CommitUpdate();
}
关于c# - 如何使用没有压缩的 SharpZipLib 将文件添加到存档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1691235/