Reputation: 493
How (or can) I zip one ZipFile up within another ZipFile?
Saving the nested ZipFile to a memory stream that is then written to the other ZipFile seems like the best way to do this, however when I use the code below the nested ZipFile (once I unpacked zip1) is 0KB large and I believe is either empty or corrupt (PeaZip says it is unreadable but Windows Explorer shows an empty folder).
Is this possible without writing the nested ZipFile to disk first and then adding that into zip1 afterwards?
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");
Upvotes: 0
Views: 199
Reputation: 331
It might be that the MemoryStream's position is at the end of the stream. You could try to set it to the begining:
stream.Position = 0;
That might work.
Upvotes: 4