when i compress a file to an already open stream that needs to stay open for further writing, my deflatestream doesnt seems to end correctly.
i need to close it to have the full compressed stream.
so as a workaround I ended writing an intermediate file so that i can close the deflatestream and then copyback the compressed stream to my main filestream.
is there a bug or something i did wrong
byte[] rBuffer = new byte[(int)fread.Length]; FileStream fout = new FileStream( tmpname, FileMode.Create ); DeflateStream zip = new DeflateStream( fout, CompressionMode.Compress ); zip.Write( rBuffer, 0, rBuffer.Length ); //needs to close here zip.Close(); |

IO.Compression.DeflateStream compression
John Gordon - MSFT
Aengus
byte[] rBuffer = new byte[(int)fread.Length];
Laptiev Igor
Your code:
zip.Write( rBuffer, 0, rBuffer.Length );
Tyr:
zip.Write( rBuffer, 0, fread.Length);
cipri
i forgot to include the read to buffer in my sample but that is not the problem
dunno if it helps but the difference between ,when i close or not, is 2 byte longer when i close it.
José Nelson
This same bug just burned me too. You must call Close() when you are done compressing. It writes two finalization bytes and one zero byte onto the end. Flush() is not good enough.
manhatma
On the bright side of things, pass a third argument to your DeflateStream constructor -- false. It's the flag that tells it to leave the passed-in stream open when DeflateStream.Dispose() is done.
Surajkb
try having a look at http://msdn.microsoft.com/msdnmag/issues/05/11/BasicInstincts/default.aspx
Yogesh Roy MSFT
StevenSw