ZipStorer takes "ownership" of stream


when I create a ZipStorer attached to a stream, the ZipStorer takes ownership of the stream. This is problematic, because the data in the created zip file isn't complete until Close() is called, but once close is called, the stream is flush()'d and close()'d. If I want to create a Zip file to a memory stream, I can't use the stream before Close() is called, because the Central Directory won't be correct. but I can't use it after Close() is called because the stream will have been closed on me.
My fix is to add a member "OwnStream" which is set to True when ZipStorer created the stream. Close() then checks to see if the stream is owned before closing and disposing of it.
This allows something like this:
var s = new MemoryStream();
using (var z = ZipStorer.Create(s,...) ) {
z.AddStream( ... )
s.Position = 0;
// now we can do something with 's', like attach it to an email message, etc.
patched ZipStorer.cs attached.

file attachments