3
votes

Using the DotNetZip Library (http://dotnetzip.codeplex.com/) is there a way to move files from one zip file into another without extracting that file to disk first? Maybe extract to a stream, then update into the other zip from that same stream?

The zip files are password protected and the data in these zip files are meant to stay that way due to their licenses. If I simply extract to disk first then update the other zip there is a chance where those files can be intercepted by the user.

1
So what have you tried so far? Seems a straightforward problem. - Henk Holterman
Working with ZipFile objects and can't seem to get it to work. I'm able to open a zip file, extract it, then open the destination one and update it, but can't figure out how to not extract it but just read the files in memory and write it to destination. Still plugging away but thought I'd ask in case someone has done this before. - user441521
I'm not familiar with dotnetZip but ZLib lets me open a readStream and a writeStream and then it's just CopyTo(). The file will be uncompresses/recompressed and decrypted/encrypted of course. You'll need the passwords. - Henk Holterman

1 Answers

3
votes

Yes, you should be able to do something like;

var ms = new MemoryStream();

using (ZipFile zip = ZipFile.Read(sourceZipFile))
{
    zip.Extract("NameOfEntryInArchive.doc", ms);
}

ms.Seek(0);

using (ZipFile zip = new ZipFile())
{
    zip.AddEntry("NameOfEntryInArchive.doc", ms);
    zip.Save(zipToCreate);
}

(see it as pseudocode since I didn't have a chance to compile)

Naturally you'll have to add your decryption/encryption to that, but those calls are equally straight forward.