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

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

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1133

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1133 **State:** closed **Merged:** Yes --- 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.
claunia added the pull-request label 2026-01-29 22:21:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1568