Zip/Unzip multiple big memorystreams

Dec 7, 2011 at 3:33 PM


I need to save several data measure streams in a same zip file.
Each MemoryStream is around 30MB, and I need to save 8 of them. 

What is the best and fastest way to achieve it ?

1) Create temporay folder -> Populate it with 8 files -> Zip the entire folder

A lot of disk access !

2) Create zipfile -> 8x AddEntry(memorystream) ->zip.Save()

I got some OutOfMemory errors

3) Create empty zipfile -> AddEntry() -> zip.Save() -> AddEntry() -> zip.Save() -> AddEntry() -> .....



Dec 7, 2011 at 9:42 PM

I'm also interested in hearing this.

I'm in the habit of wrapping my memory streams in using statements, so I don't have remember to close them, and it is very inconvenient that I have to keep the memory streams around for when I call save some time later.

I wish that when you call AddEntry()--or something like it--the ZipFile would read the the data from the stream, add it to a memory stream of its own, compressing it along the way.  So before you call Save(), ZipFile has a compressed memory stream member containing all of the data in the zip file.  This data would be smaller because it is uncompressed.  Then when you call Save() it writes to disk the data in the memory stream.

This is somewhat like how the zip package stuff works in System.IO.Packaging.  The issue there is that it includes this unnecessary [Content_Types].xml file in the zip file and doesn't seem to do as good of a job compressing certain file types.