Skip to content

Comments

Fix a usage of ReadOnly that use dispose in 7Zip#1113

Merged
adamhathcock merged 4 commits intomasterfrom
adam/fix-readonly-dispose
Jan 6, 2026
Merged

Fix a usage of ReadOnly that use dispose in 7Zip#1113
adamhathcock merged 4 commits intomasterfrom
adam/fix-readonly-dispose

Conversation

@adamhathcock
Copy link
Owner

@adamhathcock adamhathcock commented Jan 6, 2026

Maybe addresses #1105
This pull request improves stream disposal behavior and consistency across several stream types in the SharpCompress library, refactors the implementation of stream skipping utilities, and adds comprehensive tests to verify correct disposal semantics. The main changes are grouped below.

Stream disposal and leaveOpen support improvements:

  • Updated ReadOnlySubStream constructors to accept a leaveOpen parameter, ensuring the inner stream is disposed correctly based on this flag.
  • Modified SevenZipFilePart.GetCompressedStream() to explicitly set leaveOpen: false when creating a ReadOnlySubStream, ensuring proper disposal of the underlying stream.
  • Refactored LZipStream to store a reference to the original stream and updated its Dispose method to dispose the original stream only in compression mode, improving disposal correctness. [1] [2]

Stream skipping utilities refactor:

  • Simplified Stream.Skip, Stream.SkipAsync, and related methods in Utility.cs to use ReadOnlySubStream and Stream.Null, reducing buffer management complexity and improving maintainability.

Testing and verification:

  • Added a new DisposalTests suite to verify the disposal behavior of various stream implementations, including checks for correct handling of the leaveOpen parameter and always/never disposal patterns.

Minor cleanup:

  • Removed the unused IsRecording property from SharpCompressStream, streamlining the codebase.

Copilot AI review requested due to automatic review settings January 6, 2026 12:46
@adamhathcock adamhathcock enabled auto-merge January 6, 2026 13:17
@adamhathcock adamhathcock merged commit 61ecd64 into master Jan 6, 2026
5 checks passed
@adamhathcock adamhathcock deleted the adam/fix-readonly-dispose branch January 6, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant