Skip to content

Add Reset() to the Zlib-based Encoders/Decoders - #131307

Open
iremyux wants to merge 7 commits into
dotnet:mainfrom
iremyux:129090-decoder-reset
Open

Add Reset() to the Zlib-based Encoders/Decoders#131307
iremyux wants to merge 7 commits into
dotnet:mainfrom
iremyux:129090-decoder-reset

Conversation

@iremyux

@iremyux iremyux commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Adds a Reset() method to the six streamless, non-allocating zlib-based types introduced in .NET 11:

•  DeflateEncoder  /  DeflateDecoder 
•  ZLibEncoder /  ZLibDecoder 
•  GZipEncoder /  GZipDecoder 

Reset() returns an instance to its initial state so the same object can be reused for a new, independent operation.

Fixes #130465
Fixes #129090

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Reset() support to the zlib-based streamless encoders/decoders in System.IO.Compression so instances can be reused for independent compression/decompression operations, backed by a new native deflateReset export and expanded test coverage.

Changes:

  • Add native CompressionNative_DeflateReset export and managed LibraryImport wrapper plumbing.
  • Add public Reset() APIs to Deflate*, ZLib*, and GZip* encoder/decoder types and route them to zlib reset functionality.
  • Enable and extend shared encoder/decoder tests to validate reset semantics (no-op on fresh instance, reset after partial work).

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/native/libs/System.IO.Compression.Native/System.IO.Compression.Native.def Exports the new native CompressionNative_DeflateReset symbol on Windows.
src/native/libs/System.IO.Compression.Native/System.IO.Compression.Native_unixexports.src Exports the new native CompressionNative_DeflateReset symbol on Unix.
src/native/libs/System.IO.Compression.Native/pal_zlib.h Declares the PAL entrypoint for CompressionNative_DeflateReset (with documentation).
src/native/libs/System.IO.Compression.Native/pal_zlib.c Implements CompressionNative_DeflateReset via deflateReset.
src/native/libs/System.IO.Compression.Native/entrypoints.c Adds CompressionNative_DeflateReset to the resolver table for LibraryImport.
src/libraries/Common/src/Interop/Interop.zlib.cs Adds LibraryImport for CompressionNative_DeflateReset.
src/libraries/Common/src/System/IO/Compression/ZLibNative.cs Adds ZLibStreamHandle.DeflateReset() wrapper on the SafeHandle.
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateEncoder.cs Adds public Reset() that calls into DeflateReset and clears managed finished state.
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateDecoder.cs Adds public Reset() that calls InflateReset2_ and clears managed finished state.
src/libraries/System.IO.Compression/src/System/IO/Compression/ZLibEncoder.cs Adds public Reset() delegating to the underlying DeflateEncoder.
src/libraries/System.IO.Compression/src/System/IO/Compression/ZLibDecoder.cs Adds public Reset() delegating to the underlying DeflateDecoder.
src/libraries/System.IO.Compression/src/System/IO/Compression/GZipEncoder.cs Adds public Reset() delegating to the underlying DeflateEncoder.
src/libraries/System.IO.Compression/src/System/IO/Compression/GZipDecoder.cs Adds public Reset() delegating to the underlying DeflateDecoder.
src/libraries/System.IO.Compression/ref/System.IO.Compression.cs Adds the new public Reset() members to the public surface area.
src/libraries/Common/tests/System/IO/Compression/EncoderDecoderTestBase.cs Adds reset-focused tests to the shared encoder/decoder test base.
src/libraries/System.IO.Compression/tests/ZLibEncoderDecoderTestBase.cs Enables reset tests for zlib-based test suites (SupportsReset => true).
src/libraries/System.IO.Compression/tests/DeflateEncoderDecoderTests.cs Updates adapters to forward Reset() to DeflateEncoder/DeflateDecoder.
src/libraries/System.IO.Compression/tests/GZipEncoderDecoderTests.cs Updates adapters to forward Reset() to GZipEncoder/GZipDecoder.
src/libraries/System.IO.Compression/tests/ZLibEncoderDecoderTests.cs Updates adapters to forward Reset() to ZLibEncoder/ZLibDecoder.

Comment thread src/libraries/System.IO.Compression/ref/System.IO.Compression.cs
Comment thread src/native/libs/System.IO.Compression.Native/pal_zlib.h
Copilot AI review requested due to automatic review settings July 24, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/libraries/System.IO.Compression/ref/System.IO.Compression.cs:27

  • This PR adds new public API surface (e.g., DeflateDecoder.Reset() and similar Reset() methods on other encoders/decoders), but the linked issue (#130465) is only labeled api-ready-for-review and does not have the required api-approved label. Per the API approval process, new public APIs should not be implemented/merged until an approved API shape is available and linked.

Please complete API review/approval (issue gets api-approved and an approved API shape comment), then verify the ref/ changes match that approved shape; or, if approval is pending, keep these APIs out of ref/ (and out of public surface) until approval is granted.

    public sealed partial class DeflateDecoder : System.IDisposable
    {
        public DeflateDecoder() { }
        public System.Buffers.OperationStatus Decompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesConsumed, out int bytesWritten) { throw null; }
        public void Dispose() { }
        public void Reset() { }
        public static bool TryDecompress(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }

@rzikm rzikm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once API is approved

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI review requested due to automatic review settings July 28, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateEncoder.cs:304

  • The Reset() remarks say the encoder preserves only “compression quality and window size”, but the underlying zlib deflateReset also preserves the other initialization settings (notably the compression strategy when constructed via ZLibCompressionOptions). Updating the remarks avoids underspecifying the preserved settings.
        /// <remarks>
        /// The encoder keeps the compression quality and window size it was created with. Any pending output or unflushed input from a previous, unfinished compression is discarded.
        /// </remarks>

src/libraries/System.IO.Compression/src/System/IO/Compression/ZLibEncoder.cs:119

  • The Reset() remarks currently claim only “compression quality and window size” are preserved. Since ZLibEncoder is backed by DeflateEncoder+zlib deflateReset, the encoder also preserves the other initialization settings (e.g., compression strategy from ZLibCompressionOptions). Consider updating the remarks to reflect that.
        /// <remarks>
        /// The encoder keeps the compression quality and window size it was created with. Any pending output or unflushed input from a previous, unfinished compression is discarded.
        /// </remarks>

src/libraries/System.IO.Compression/src/System/IO/Compression/GZipEncoder.cs:127

  • The Reset() remarks currently claim only “compression quality and window size” are preserved. Since GZipEncoder is backed by DeflateEncoder+zlib deflateReset, the encoder also preserves the other initialization settings (e.g., compression strategy from ZLibCompressionOptions). Consider updating the remarks to reflect that.
        /// <remarks>
        /// The encoder keeps the compression quality and window size it was created with. Any pending output or unflushed input from a previous, unfinished compression is discarded.
        /// </remarks>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.IO.Compression.ZLibDecoder Api in net11.0 - refinemnt needed in API or documentation

4 participants