Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

GZipStream not working as expected on compress. #556

@jgauffin

Description

@jgauffin

I'm using .NET standard and had ported some code from .NET 4.5.2.

Expected outcome:

Dispose() or Flush() should be enough for the compressed contents to get copied to the inner stream.

Actual outcome

Both Flush and Dispose are required to get the correct amount of bytes back from the gzipstream:

using (var gzip = new GZipStream(ms, CompressionLevel.Optimal, true))
{
    gzip.Write(jsonBytes, 0, jsonBytes.Length);
    gzip.Flush();
}
buffer = ms.ToArray();

With just flush, I get 190 instead of 200 bytes:

using (var gzip = new GZipStream(ms, CompressionLevel.Optimal))
{
    gzip.Write(jsonBytes, 0, jsonBytes.Length);
    gzip.Flush();
    buffer = ms.ToArray();
}

With only Dispose i get 194 of the 200 expected bytes:

using (var gzip = new GZipStream(ms, CompressionLevel.Optimal, true))
{
    gzip.Write(jsonBytes, 0, jsonBytes.Length);
}
buffer = ms.ToArray();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions