如何使用SharpZipLib向Zip归档添加无压缩的文件?
谷歌上的示例似乎非常稀少。
如何使用SharpZipLib向Zip归档添加无压缩的文件?
谷歌上的示例似乎非常稀少。
您可以使用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();
}