Closed dguder closed 7 years ago
Hi, sounds reasonable, please provide the pull request.
Really, this is a problem. This class should NOT close a stream which it didn't create. I'm using it on a application, to create a zipfile (in a memory stream) which I'm going to send to my enduser. Right now,I can't send him a valid file, because I can't use Close to save the central directory information. If you don't want to change this comportment, can you at least add a method to save the central directory information without closing the stream ?
I fixed it right now creating an optional parameter on Close. Maybe it would have been better to create a CloseWithoutClosingExternalStream methode ? (not sure..)
If you are using a memory stream, you can always recreate another memory stream based on your underlying byte array. Something like:
memoryStream = new MemoryStream(memoryStream.ToArray());
I'm trying to use this class in a small WCF project where I don't want to add another 3rd party lib. I want to use the stream mode for packaging and then send the zip stream to another machine. Unfortunately the internal zipfilestream is closed and disposed within the
Close()
method. If I don't close the zip, then theEndRecord
is not written. But when I close the zip then the underlying stream is closed. My suggestion is to set a flag when a filename is provided forOpen()
orCreate()
. When this is set, thenZipFileStream.Dispose();
andZipFileStream = null;
in functionClose()
should be omitted. I have a working solution here and can provide a pull request later.