Friday, September 3, 2021

GZipStream issue

Recently I was required to include some functionality which consists of compression and decompression of data.  To accomplish this task I made use of the GZipStream object.

Initially, I was using the following code for compression:

using var gs = new GZipStream(mso, CompressionMode.Compress);{
msi.CopyTo(gs);

After trying using this code, no compressed data was being produced.  After changing the code to the below, compressed data was being produced correctly.


using var gs = new GZipStream(mso, CompressionMode.Compress);{
{
        msi.CopyTo(gs);
}

The functionality for the above shared code should be identical, but for some reason it behaves differently.

Following the above, I did some additional tests using a different Compression Mode as Decompress.  Use both code samples shown above, during decompression issue wasn't reproduced.

No comments: