Creating Zip from Stream

Dec 10, 2009 at 10:05 AM
Edited Dec 10, 2009 at 10:18 AM

I have an object which I currently serialize to a file.  It gets very large so I want to zip it.  So I serialize itain to a MemoryStream and then add it to the zip.  The memory stream does contain the serialized object but the zip file contains an empty file.  I would appreciate some help on why this is happening.  My code is below



var ms = new MemoryStream();
var binSerializer = new BinaryFormatter();
binSerializer.Serialize(ms, saveFile);
using (var zip = new ZipFile()) {
       ZipEntry e = zip.AddEntry(filename, "", ms);
Dec 10, 2009 at 10:12 AM
Edited Dec 10, 2009 at 10:16 AM


Read before you go into print.....  Sorry Folks I now saw the post below with the same problem and I can confirm that converting the stream to a byte array first does indeed work, as does setting the stream position to zero before trying to zip it.