如何使用DotNetZip压缩ZipFile



我如何(或可以)压缩一个ZipFile在另一个ZipFile?

将嵌套ZipFile保存到内存流中,然后写入另一个ZipFile似乎是最好的方法,但是当我使用嵌套ZipFile下面的代码时(一旦我解压缩zip1)是0KB大,我认为是空的或损坏的(PeaZip说它是不可读的,但Windows资源管理器显示一个空文件夹)。

如果不首先将嵌套的ZipFile写入磁盘,然后添加到zip1中,这是可能的吗?

        ZipFile zip1 = new ZipFile()
        {
            ParallelDeflateThreshold = -1
        };
        ZipFile zip2 = new ZipFile()
        {
            ParallelDeflateThreshold = -1
        };
        zip1.AddEntry("test.txt", "hello world");
        zip2.AddEntry("test2.txt", "hello dark world");
        MemoryStream stream = new MemoryStream();
        zip2.Save(stream);
        Console.WriteLine(Encoding.ASCII.GetString(stream.ToArray()));
        zip1.AddEntry("test.zip", stream);
        zip2.Dispose();
        zip1.Save("C:/output.zip");

可能MemoryStream的位置在流的末尾。您可以尝试将其设置为开头:

stream.Position = 0;

最新更新