c# - 如何使用没有压缩的 SharpZipLib 将文件添加到存档?

标签 c# sharpziplib

如何使用没有压缩的 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/

相关文章:

c# - 获取字符串中模式的匹配项

c# - 从 Request.Files 中删除文件

c# - SharpZipLib ~ 如何从 zip 中提取特定文件

C# with SharpZipLib - SharpZipLib 与 Winzip 和 XP 的兼容性?

c# - 您如何急切加载一个实体可能拥有的所有子集合?

c# - 防止表单多次显示

c# - ServicePointManager.ServerCertificateValidationCallback 的目的是什么?

java - 将 DeflaterInputStream 功能移植到 .net

sharpziplib - 适用于 .NET Core 的 C# SharpZipLib

c# - 在创建 zip 文件时发送该文件