[PR #1133] [MERGED] Add async I/O support for SevenZip archive initialization #1563

Open
opened 2026-01-29 22:21:09 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1133
Author: @Copilot
Created: 1/15/2026
Status: Merged
Merged: 1/16/2026
Merged by: @adamhathcock

Base: adam/async-creationHead: copilot/sub-pr-1132


📝 Commits (5)

  • 0b2158f Initial plan
  • bbba2e6 Initial plan for fixing SevenZipArchive_LZMA_AsyncStreamExtraction test
  • 9bb670a Fix SevenZipArchive async stream handling by adding async Open and ReadDatabase methods
  • 491beab uncomment tests
  • f4ce4cb fix tests for both frameworks

📊 Changes

5 files changed (+306 additions, -14 deletions)

View changed files

📝 src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs (+73 -4)
📝 src/SharpCompress/Common/SevenZip/ArchiveReader.cs (+146 -0)
📝 src/SharpCompress/Factories/ArjFactory.cs (+1 -2)
📝 src/SharpCompress/packages.lock.json (+3 -3)
📝 tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs (+83 -5)

📄 Description

SevenZipArchive was performing synchronous reads during archive initialization, causing failures when used with async-only streams via OpenAsyncArchive.

Changes:

  • ArchiveReader: Added OpenAsync and ReadDatabaseAsync methods that use ReadExactAsync instead of synchronous Read calls
  • SevenZipArchive:
    • Added LoadFactoryAsync to initialize archive database asynchronously
    • Overrode LoadEntriesAsync to use async loading path
    • Converted LoadEntries to iterator pattern (yield return) for proper lazy evaluation

The async and sync code paths are now properly separated, with EntriesAsync using fully async I/O operations:

// Async path now works with async-only streams
await using var archive = await ArchiveFactory.OpenAsyncArchive(asyncOnlyStream);
await foreach (var entry in archive.EntriesAsync)
{
    await using var stream = await entry.OpenEntryStreamAsync();
    // Extract asynchronously
}

Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1133 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/15/2026 **Status:** ✅ Merged **Merged:** 1/16/2026 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `adam/async-creation` ← **Head:** `copilot/sub-pr-1132` --- ### 📝 Commits (5) - [`0b2158f`](https://github.com/adamhathcock/sharpcompress/commit/0b2158f74caaaadbd1a4914f6353730ad1ed4959) Initial plan - [`bbba2e6`](https://github.com/adamhathcock/sharpcompress/commit/bbba2e6c7ab3b96e286dcdcef2dacd5714a0023e) Initial plan for fixing SevenZipArchive_LZMA_AsyncStreamExtraction test - [`9bb670a`](https://github.com/adamhathcock/sharpcompress/commit/9bb670ad196acde024935e0f9fa4ec86075b5d6e) Fix SevenZipArchive async stream handling by adding async Open and ReadDatabase methods - [`491beab`](https://github.com/adamhathcock/sharpcompress/commit/491beabe032222ee3eb8559ae6b9a0bf819b4d2c) uncomment tests - [`f4ce4cb`](https://github.com/adamhathcock/sharpcompress/commit/f4ce4cbad8855a482fd5d242cd90ea3ef26e4983) fix tests for both frameworks ### 📊 Changes **5 files changed** (+306 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs` (+73 -4) 📝 `src/SharpCompress/Common/SevenZip/ArchiveReader.cs` (+146 -0) 📝 `src/SharpCompress/Factories/ArjFactory.cs` (+1 -2) 📝 `src/SharpCompress/packages.lock.json` (+3 -3) 📝 `tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs` (+83 -5) </details> ### 📄 Description SevenZipArchive was performing synchronous reads during archive initialization, causing failures when used with async-only streams via `OpenAsyncArchive`. **Changes:** * **ArchiveReader**: Added `OpenAsync` and `ReadDatabaseAsync` methods that use `ReadExactAsync` instead of synchronous `Read` calls * **SevenZipArchive**: - Added `LoadFactoryAsync` to initialize archive database asynchronously - Overrode `LoadEntriesAsync` to use async loading path - Converted `LoadEntries` to iterator pattern (yield return) for proper lazy evaluation The async and sync code paths are now properly separated, with `EntriesAsync` using fully async I/O operations: ```csharp // Async path now works with async-only streams await using var archive = await ArchiveFactory.OpenAsyncArchive(asyncOnlyStream); await foreach (var entry in archive.EntriesAsync) { await using var stream = await entry.OpenEntryStreamAsync(); // Extract asynchronously } ``` <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:21:09 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1563