Add leaveOpen parameter to LZipStream and BZip2Stream#1145
Merged
adamhathcock merged 3 commits intomasterfrom Jan 19, 2026
Merged
Add leaveOpen parameter to LZipStream and BZip2Stream#1145adamhathcock merged 3 commits intomasterfrom
adamhathcock merged 3 commits intomasterfrom
Conversation
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
…isposal Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add leaveOpen parameter to LZipStream and BZip2Stream
Add leaveOpen parameter to LZipStream and BZip2Stream
Jan 19, 2026
adamhathcock
approved these changes
Jan 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds a leaveOpen parameter to LZipStream and BZip2Stream compression streams, addressing a breaking change introduced in PR #1113. The parameter controls whether the underlying stream should remain open after the compression stream is disposed, matching the behavior of other compression streams like ZStandard.
Changes:
- Added
leaveOpenparameter (defaults tofalse) toBZip2StreamandLZipStreamconstructors - Updated internal streams (
CBZip2InputStream,CBZip2OutputStream,LzmaStream) to propagate and respect the flag - Fixed disposal logic in
CBZip2InputStream.BsFinishedWithStream()which was disposing streams unconditionally
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/SharpCompress.Test/Streams/LeaveOpenBehaviorTests.cs |
New comprehensive test file covering compress/decompress modes for both BZip2Stream and LZipStream with leaveOpen true/false |
tests/SharpCompress.Test/Streams/DisposalTests.cs |
Updated existing disposal tests to verify leaveOpen behavior for LZipStream and BZip2Stream |
src/SharpCompress/Compressors/BZip2/BZip2Stream.cs |
Added leaveOpen parameter to constructor and propagated it to internal streams |
src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs |
Added leaveOpen field and updated disposal logic to conditionally dispose the underlying stream |
src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs |
Added leaveOpen field and fixed disposal logic in both Dispose() and BsFinishedWithStream() methods |
src/SharpCompress/Compressors/LZMA/LZipStream.cs |
Added leaveOpen parameter and updated compress mode disposal logic |
src/SharpCompress/Compressors/LZMA/LzmaStream.cs |
Added leaveOpen parameter to all decoder constructors and updated disposal logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
adamhathcock
added a commit
that referenced
this pull request
Jan 19, 2026
…meter-lzipstream Add leaveOpen parameter to LZipStream and BZip2Stream
adamhathcock
added a commit
that referenced
this pull request
Jan 19, 2026
Merge pull request #1145 from adamhathcock/copilot/add-leaveopen-para…
This was referenced Feb 11, 2026
This was referenced Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #1113 changed disposal behavior for
LZipStreamandBZip2Stream, breaking code that expected the underlying stream to remain open. These streams lacked theleaveOpenparameter available in other compression streams likeZStandard.Changes
leaveOpenparameter toLZipStreamandBZip2Streamconstructors (defaults tofalsefor backward compatibility)CBZip2InputStream,CBZip2OutputStream,LzmaStream) to propagate and respect theleaveOpenflagCBZip2InputStream.BsFinishedWithStream()which was disposing streams unconditionally during decompressionUsage
Testing
Added comprehensive tests in
LeaveOpenBehaviorTests.cscovering compress/decompress modes for both streams withleaveOpen=true/false.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.