Skip to content

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

Draft
iremyux wants to merge 6 commits into
dotnet:mainfrom
iremyux:129090-decoder-reset
Draft

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

Conversation

@iremyux

@iremyux iremyux commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Implements #130465

@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 on lines 21 to 27
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; }
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

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.

3 participants