I am wondering how to do the same thing as the original poster is. I know how to do the actual zipping in memory but I do not know how (or if it is possible) to add files, in the form of byte array, to the zip in memory.
From what I understand, the process is as follows:
- Create a ZipOutputStream.
- Create a ZipEntry and pass it the path of the file to add.
- Call ZipOutputStream.PutNextEntry(ZipEntry).
- Close streams, etc.
My question is this: Can I somehow create a ZipEntry with an array of bytes, instead of a file path? Otherwise, I cannot see how you could do this in memory. I tried out the ZipOutputStream.Read() method which takes in an array of bytes but I receive a "DeflaterOutputStream Read not supported" exception.
I am using assembly version 0.85.5.452 of the ICSharpCode.SharpZipLib library with .NET Framework 3.5.
EDIT: Found the solution (from a reply in another thread). Basically the ZipEntry is created with the filename as the string (which I thought needed to be an actual path to the file) and the MemoryStream's WriteTo() method is used and the ZipOutputStream is sent as an argument:
ZipEntry zipEntry = new ZipEntry("filename");
zipOutputStream.PutNextEntry(entry);
fileMemoryStream.WriteTo(zos)