Skip to content

fix: Change LeaveStreamOpen default from true to false#1293

Merged
adamhathcock merged 9 commits into
adamhathcock:masterfrom
puk06:fix/leave-stream-open-default
Apr 21, 2026
Merged

fix: Change LeaveStreamOpen default from true to false#1293
adamhathcock merged 9 commits into
adamhathcock:masterfrom
puk06:fix/leave-stream-open-default

Conversation

@puk06
Copy link
Copy Markdown
Contributor

@puk06 puk06 commented Apr 20, 2026

As of v0.21, the library is documented to close wrapped streams by default. However, the ReaderOptions.LeaveStreamOpen property defaulted to true, which contradicted the documented behavior and caused file locks when deleting archives after extraction.

Changes:

  • Set LeaveStreamOpen = false as the default (consistent with v0.21 design)
  • Updated ReaderOptions.cs with comprehensive documentation explaining:
    • File-based vs caller-provided stream handling
    • When to use LeaveStreamOpen = true
    • Usage examples for both scenarios
  • Updated AGENTS.md Stream Handling Rules section with:
    • Clear explanation of default disposal behavior
    • Overload differences (file-based vs stream-based)
    • Guidance on using ForExternalStream preset

This ensures the implementation matches the documented behavior and prevents unexpected file locking issues during archive deletion.

Fixes: File deletion failures after archive extraction


Please note that while this change aligns with the documented specification, it is a breaking change that may affect existing code.
The removal of the explicit LeaveStreamOpen=false override in ZipArchive was motivated by the fact that false is now the default. However, since other Archive types originally relied on the default value of true, existing code that does not explicitly specify ReaderOptions may behave differently than before.
Breaking changes of this nature should be documented somewhere. That said, since I'm not familiar enough with where exactly the documentation should be updated, I've opted not to include those changes in this pull request.

As of v0.21, the library is documented to close wrapped streams by default.
However, the ReaderOptions.LeaveStreamOpen property defaulted to true, which
contradicted the documented behavior and caused file locks when deleting
archives after extraction.

Changes:
- Set LeaveStreamOpen = false as the default (consistent with v0.21 design)
- Updated ReaderOptions.cs with comprehensive documentation explaining:
  * File-based vs caller-provided stream handling
  * When to use LeaveStreamOpen = true
  * Usage examples for both scenarios
- Updated AGENTS.md Stream Handling Rules section with:
  * Clear explanation of default disposal behavior
  * Overload differences (file-based vs stream-based)
  * Guidance on using ForExternalStream preset

This ensures the implementation matches the documented behavior and prevents
unexpected file locking issues during archive deletion.

Fixes: File deletion failures after archive extraction
Copilot AI review requested due to automatic review settings April 20, 2026 13:37

This comment was marked as outdated.

@puk06 puk06 marked this pull request as draft April 20, 2026 13:52
@adamhathcock adamhathcock marked this pull request as ready for review April 20, 2026 13:59
@adamhathcock adamhathcock marked this pull request as draft April 20, 2026 13:59
@puk06
Copy link
Copy Markdown
Contributor Author

puk06 commented Apr 21, 2026

Please note that while this change aligns with the documented specification, it is a breaking change that may affect existing code.
The removal of the explicit LeaveStreamOpen=false override in ZipArchive was motivated by the fact that false is now the default. However, since other Archive types originally relied on the default value of true, existing code that does not explicitly specify ReaderOptions may behave differently than before.
Breaking changes of this nature should be documented somewhere. That said, since I'm not familiar enough with where exactly the documentation should be updated, I've opted not to include those changes in this pull request.

@puk06 puk06 marked this pull request as ready for review April 21, 2026 00:26
Copilot AI review requested due to automatic review settings April 21, 2026 00:26

This comment was marked as outdated.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 00:32

This comment was marked as outdated.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 00:40

This comment was marked as outdated.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 00:48

This comment was marked as outdated.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 01:09

This comment was marked as outdated.

tonycknight pushed a commit to tonycknight/microbroker that referenced this pull request May 31, 2026
Updated [SharpCompress](https://github.com/adamhathcock/sharpcompress)
from 0.48.1 to 0.49.0.

<details>
<summary>Release notes</summary>

_Sourced from [SharpCompress's
releases](https://github.com/adamhathcock/sharpcompress/releases)._

## 0.49.0

This should contain a lot of write async fixes and some breaking API
changes that fix previous broke `net48` usage

## What's Changed
* Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by
@​Copilot in adamhathcock/sharpcompress#1244
* Some API clean up from GPT 5.4 by @​adamhathcock in
adamhathcock/sharpcompress#1243
* Release to master by @​adamhathcock in
adamhathcock/sharpcompress#1267
* Fix three BLAKE2sp correctness bugs and eliminate allocations in hot
path by @​coderb in
adamhathcock/sharpcompress#1266
* Corrected async examples. by @​dlemstra in
adamhathcock/sharpcompress#1277
* Fix setting invalid access time fails extraction by @​aromaa in
adamhathcock/sharpcompress#1279
* Fix incorrect code examples in docs for sync/async usage by @​Copilot
in adamhathcock/sharpcompress#1280
* Replace APPNOTE.TXT contents with reference link note by @​puk06 in
adamhathcock/sharpcompress#1286
* Release to Master by @​adamhathcock in
adamhathcock/sharpcompress#1274
* update docs for tar gap analysis and XZ usage by @​adamhathcock in
adamhathcock/sharpcompress#1288
* Add a PooledMemoryStream to avoid allocating by @​adamhathcock in
adamhathcock/sharpcompress#1275
* fix: Change LeaveStreamOpen default from true to false by @​puk06 in
adamhathcock/sharpcompress#1293
* Fix usage of ReaderOptions and pre-defined values by @​adamhathcock in
adamhathcock/sharpcompress#1295
* Enforce seekable, readable and writable on streams by @​adamhathcock
in adamhathcock/sharpcompress#1297
* Add ArchiveInformation record for consolidated archive detection and
capability inspection by @​Copilot in
adamhathcock/sharpcompress#1299
* merge release to master by @​adamhathcock in
adamhathcock/sharpcompress#1314
* Some clean up and test clean up by @​adamhathcock in
adamhathcock/sharpcompress#1321
* Finish Write Async by @​adamhathcock in
adamhathcock/sharpcompress#1323
* More complete Tar implementation: USTAR, PAX, etc. by @​adamhathcock
in adamhathcock/sharpcompress#1289
* Add Polysharp and adjustments that do not break legacy frameworks by
@​adamhathcock in
adamhathcock/sharpcompress#1330
* Fix null `IVolume.FileName` for single-volume file-based archives by
@​Copilot in adamhathcock/sharpcompress#1333
* Add skills by @​adamhathcock in
adamhathcock/sharpcompress#1332
* add AOT smoke and missing tests by @​adamhathcock in
adamhathcock/sharpcompress#1334

## New Contributors
* @​dlemstra made their first contribution in
adamhathcock/sharpcompress#1277
* @​aromaa made their first contribution in
adamhathcock/sharpcompress#1279
* @​puk06 made their first contribution in
adamhathcock/sharpcompress#1286

**Full Changelog**:
adamhathcock/sharpcompress@0.48.1...0.49.0

## 0.49.0-beta.140

## What's Changed
* Add Polysharp and adjustments that do not break legacy frameworks by
@​adamhathcock in
adamhathcock/sharpcompress#1330


**Full Changelog**:
adamhathcock/sharpcompress@0.49.0-beta.136...0.49.0-beta.140

## 0.49.0-beta.136

## What's Changed
* Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by
@​Copilot in adamhathcock/sharpcompress#1244
* Some API clean up from GPT 5.4 by @​adamhathcock in
adamhathcock/sharpcompress#1243
* Release to master by @​adamhathcock in
adamhathcock/sharpcompress#1267
* Fix three BLAKE2sp correctness bugs and eliminate allocations in hot
path by @​coderb in
adamhathcock/sharpcompress#1266
* Corrected async examples. by @​dlemstra in
adamhathcock/sharpcompress#1277
* Fix setting invalid access time fails extraction by @​aromaa in
adamhathcock/sharpcompress#1279
* Fix incorrect code examples in docs for sync/async usage by @​Copilot
in adamhathcock/sharpcompress#1280
* Replace APPNOTE.TXT contents with reference link note by @​puk06 in
adamhathcock/sharpcompress#1286
* Release to Master by @​adamhathcock in
adamhathcock/sharpcompress#1274
* update docs for tar gap analysis and XZ usage by @​adamhathcock in
adamhathcock/sharpcompress#1288
* Add a PooledMemoryStream to avoid allocating by @​adamhathcock in
adamhathcock/sharpcompress#1275
* fix: Change LeaveStreamOpen default from true to false by @​puk06 in
adamhathcock/sharpcompress#1293
* Fix usage of ReaderOptions and pre-defined values by @​adamhathcock in
adamhathcock/sharpcompress#1295
* Enforce seekable, readable and writable on streams by @​adamhathcock
in adamhathcock/sharpcompress#1297
* Add ArchiveInformation record for consolidated archive detection and
capability inspection by @​Copilot in
adamhathcock/sharpcompress#1299
* merge release to master by @​adamhathcock in
adamhathcock/sharpcompress#1314
* Some clean up and test clean up by @​adamhathcock in
adamhathcock/sharpcompress#1321
* Finish Write Async by @​adamhathcock in
adamhathcock/sharpcompress#1323
* More complete Tar implementation: USTAR, PAX, etc. by @​adamhathcock
in adamhathcock/sharpcompress#1289

## New Contributors
* @​dlemstra made their first contribution in
adamhathcock/sharpcompress#1277
* @​aromaa made their first contribution in
adamhathcock/sharpcompress#1279
* @​puk06 made their first contribution in
adamhathcock/sharpcompress#1286

**Full Changelog**:
adamhathcock/sharpcompress@0.48.1...0.49.0-beta1

Commits viewable in [compare
view](adamhathcock/sharpcompress@0.48.1...0.49.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=SharpCompress&package-manager=nuget&previous-version=0.48.1&new-version=0.49.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
tonycknight pushed a commit to tonycknight/discorss that referenced this pull request Jun 1, 2026
Updated [SharpCompress](https://github.com/adamhathcock/sharpcompress)
from 0.48.1 to 0.49.1.

<details>
<summary>Release notes</summary>

_Sourced from [SharpCompress's
releases](https://github.com/adamhathcock/sharpcompress/releases)._

## 0.49.1

## What's Changed
* Close writable entry streams during async archive disposal by
@​Copilot in adamhathcock/sharpcompress#1338
* Restore `WriteToDirectoryAsync` progress callbacks for solid 7z
archives by @​Copilot in
adamhathcock/sharpcompress#1340
* Try to fix global.json to avoid churn in locks by @​adamhathcock in
adamhathcock/sharpcompress#1341
* Fix tar archive enumeration after fully reading entry streams by
@​adamhathcock in
adamhathcock/sharpcompress#1342


**Full Changelog**:
adamhathcock/sharpcompress@0.49.0...0.49.1

## 0.49.0

This should contain a lot of write async fixes and some breaking API
changes that fix previous broke `net48` usage

## What's Changed
* Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by
@​Copilot in adamhathcock/sharpcompress#1244
* Some API clean up from GPT 5.4 by @​adamhathcock in
adamhathcock/sharpcompress#1243
* Release to master by @​adamhathcock in
adamhathcock/sharpcompress#1267
* Fix three BLAKE2sp correctness bugs and eliminate allocations in hot
path by @​coderb in
adamhathcock/sharpcompress#1266
* Corrected async examples. by @​dlemstra in
adamhathcock/sharpcompress#1277
* Fix setting invalid access time fails extraction by @​aromaa in
adamhathcock/sharpcompress#1279
* Fix incorrect code examples in docs for sync/async usage by @​Copilot
in adamhathcock/sharpcompress#1280
* Replace APPNOTE.TXT contents with reference link note by @​puk06 in
adamhathcock/sharpcompress#1286
* Release to Master by @​adamhathcock in
adamhathcock/sharpcompress#1274
* update docs for tar gap analysis and XZ usage by @​adamhathcock in
adamhathcock/sharpcompress#1288
* Add a PooledMemoryStream to avoid allocating by @​adamhathcock in
adamhathcock/sharpcompress#1275
* fix: Change LeaveStreamOpen default from true to false by @​puk06 in
adamhathcock/sharpcompress#1293
* Fix usage of ReaderOptions and pre-defined values by @​adamhathcock in
adamhathcock/sharpcompress#1295
* Enforce seekable, readable and writable on streams by @​adamhathcock
in adamhathcock/sharpcompress#1297
* Add ArchiveInformation record for consolidated archive detection and
capability inspection by @​Copilot in
adamhathcock/sharpcompress#1299
* merge release to master by @​adamhathcock in
adamhathcock/sharpcompress#1314
* Some clean up and test clean up by @​adamhathcock in
adamhathcock/sharpcompress#1321
* Finish Write Async by @​adamhathcock in
adamhathcock/sharpcompress#1323
* More complete Tar implementation: USTAR, PAX, etc. by @​adamhathcock
in adamhathcock/sharpcompress#1289
* Add Polysharp and adjustments that do not break legacy frameworks by
@​adamhathcock in
adamhathcock/sharpcompress#1330
* Fix null `IVolume.FileName` for single-volume file-based archives by
@​Copilot in adamhathcock/sharpcompress#1333
* Add skills by @​adamhathcock in
adamhathcock/sharpcompress#1332
* add AOT smoke and missing tests by @​adamhathcock in
adamhathcock/sharpcompress#1334

## New Contributors
* @​dlemstra made their first contribution in
adamhathcock/sharpcompress#1277
* @​aromaa made their first contribution in
adamhathcock/sharpcompress#1279
* @​puk06 made their first contribution in
adamhathcock/sharpcompress#1286

**Full Changelog**:
adamhathcock/sharpcompress@0.48.1...0.49.0

## 0.49.0-beta.140

## What's Changed
* Add Polysharp and adjustments that do not break legacy frameworks by
@​adamhathcock in
adamhathcock/sharpcompress#1330


**Full Changelog**:
adamhathcock/sharpcompress@0.49.0-beta.136...0.49.0-beta.140

## 0.49.0-beta.136

## What's Changed
* Rename IWriteableArchiveFactory.cs to IWritableArchiveFactory.cs by
@​Copilot in adamhathcock/sharpcompress#1244
* Some API clean up from GPT 5.4 by @​adamhathcock in
adamhathcock/sharpcompress#1243
* Release to master by @​adamhathcock in
adamhathcock/sharpcompress#1267
* Fix three BLAKE2sp correctness bugs and eliminate allocations in hot
path by @​coderb in
adamhathcock/sharpcompress#1266
* Corrected async examples. by @​dlemstra in
adamhathcock/sharpcompress#1277
* Fix setting invalid access time fails extraction by @​aromaa in
adamhathcock/sharpcompress#1279
* Fix incorrect code examples in docs for sync/async usage by @​Copilot
in adamhathcock/sharpcompress#1280
* Replace APPNOTE.TXT contents with reference link note by @​puk06 in
adamhathcock/sharpcompress#1286
* Release to Master by @​adamhathcock in
adamhathcock/sharpcompress#1274
* update docs for tar gap analysis and XZ usage by @​adamhathcock in
adamhathcock/sharpcompress#1288
* Add a PooledMemoryStream to avoid allocating by @​adamhathcock in
adamhathcock/sharpcompress#1275
* fix: Change LeaveStreamOpen default from true to false by @​puk06 in
adamhathcock/sharpcompress#1293
* Fix usage of ReaderOptions and pre-defined values by @​adamhathcock in
adamhathcock/sharpcompress#1295
* Enforce seekable, readable and writable on streams by @​adamhathcock
in adamhathcock/sharpcompress#1297
* Add ArchiveInformation record for consolidated archive detection and
capability inspection by @​Copilot in
adamhathcock/sharpcompress#1299
* merge release to master by @​adamhathcock in
adamhathcock/sharpcompress#1314
* Some clean up and test clean up by @​adamhathcock in
adamhathcock/sharpcompress#1321
* Finish Write Async by @​adamhathcock in
adamhathcock/sharpcompress#1323
* More complete Tar implementation: USTAR, PAX, etc. by @​adamhathcock
in adamhathcock/sharpcompress#1289

## New Contributors
* @​dlemstra made their first contribution in
adamhathcock/sharpcompress#1277
* @​aromaa made their first contribution in
adamhathcock/sharpcompress#1279
* @​puk06 made their first contribution in
adamhathcock/sharpcompress#1286

**Full Changelog**:
adamhathcock/sharpcompress@0.48.1...0.49.0-beta1

Commits viewable in [compare
view](adamhathcock/sharpcompress@0.48.1...0.49.1).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=SharpCompress&package-manager=nuget&previous-version=0.48.1&new-version=0.49.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Jun 1, 2026
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.

3 participants