[PR #976] [CLOSED] Add async/await support for all Stream I/O operations #1392

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/976
Author: @Copilot
Created: 10/25/2025
Status: Closed

Base: masterHead: copilot/convert-stream-access-to-async


📝 Commits (7)

  • 06deca5 Initial plan
  • 8f54cd4 Initial commit - Planning async Stream conversion
  • 3404607 Add async infrastructure to core I/O classes and interfaces
  • fcb3838 Implement async methods across all Archive entries and extension methods
  • 7799d2d Update README and USAGE documentation with async examples
  • 999a1eb Add comprehensive async tests demonstrating new functionality
  • 1cd2459 Fix test to use deterministic DateTime value per code review

📊 Changes

20 files changed (+1083 additions, -15 deletions)

View changed files

📝 README.md (+78 -0)
📝 USAGE.md (+143 -0)
📝 src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs (+8 -0)
📝 src/SharpCompress/Archives/IArchiveEntry.cs (+8 -0)
📝 src/SharpCompress/Archives/Rar/RarArchiveEntry.cs (+5 -0)
📝 src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs (+5 -0)
📝 src/SharpCompress/Archives/Tar/TarArchiveEntry.cs (+5 -0)
📝 src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs (+5 -0)
📝 src/SharpCompress/Common/ExtractionMethods.cs (+113 -0)
📝 src/SharpCompress/IO/SharpCompressStream.cs (+139 -12)
📝 src/SharpCompress/IO/SourceStream.cs (+102 -0)
📝 src/SharpCompress/Readers/AbstractReader.cs (+38 -0)
📝 src/SharpCompress/Readers/IReader.cs (+9 -0)
📝 src/SharpCompress/Readers/IReaderExtensions.cs (+62 -0)
📝 src/SharpCompress/Utility.cs (+135 -0)
📝 src/SharpCompress/Writers/AbstractWriter.cs (+15 -0)
📝 src/SharpCompress/Writers/IWriter.cs (+8 -0)
📝 src/SharpCompress/Writers/IWriterExtensions.cs (+69 -0)
📝 src/SharpCompress/packages.lock.json (+3 -3)
tests/SharpCompress.Test/AsyncTests.cs (+133 -0)

📄 Description

All I/O operations now support async/await with CancellationToken. Methods performing async operations are suffixed with Async.

Changes

Core Infrastructure

  • SharpCompressStream, SourceStream - Added ReadAsync(), WriteAsync(), FlushAsync()
  • Utility methods - Added TransferToAsync(), SkipAsync() with CancellationToken support

Public APIs

  • IReader.WriteEntryToAsync() - Extract entries asynchronously
  • IWriter.WriteAsync() - Write entries asynchronously
  • IArchiveEntry.OpenEntryStreamAsync() - Open entry streams asynchronously

Extension Methods

  • reader.WriteAllToDirectoryAsync() - Bulk async extraction
  • writer.WriteAllAsync() - Bulk async compression
  • All methods accept optional CancellationToken

Archive Format Support

  • All formats (GZip, Tar, Zip, Rar, SevenZip) implement async entry stream opening

Usage

Async Reading:

using var reader = ReaderFactory.Open(stream);
await reader.WriteAllToDirectoryAsync(@"C:\output", options, cancellationToken);

Async Writing:

using var writer = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate);
await writer.WriteAllAsync(@"D:\files", "*", SearchOption.AllDirectories, cancellationToken);

Async Entry Access:

using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken);
await entryStream.CopyToAsync(outputStream, cancellationToken);

Compatibility

  • All synchronous methods remain unchanged - no breaking changes
  • Framework support: net48, net481, netstandard2.0, net6.0, net8.0
  • Older frameworks use Microsoft.Bcl.AsyncInterfaces polyfill (already referenced)

Documentation

  • README.md - Added async overview and examples
  • USAGE.md - Added comprehensive async patterns section
  • New test file AsyncTests.cs with 6 async scenarios
Original prompt

Convert all Stream access to be async. All IO should go through asynchronous methods now. Methods using async should be renamed to be Async. .NET legacy (.net framework 4.8 and 4.8.1 and .net standard) might need something different. Use compiler flags if necessary. Update the README when done.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


🔄 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/976 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 10/25/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `copilot/convert-stream-access-to-async` --- ### 📝 Commits (7) - [`06deca5`](https://github.com/adamhathcock/sharpcompress/commit/06deca51e23580afdb27a90ba6d4c2a176616efb) Initial plan - [`8f54cd4`](https://github.com/adamhathcock/sharpcompress/commit/8f54cd4a962bb357c8db9ba09a6f6983faa678d3) Initial commit - Planning async Stream conversion - [`3404607`](https://github.com/adamhathcock/sharpcompress/commit/3404607414e8f4b71632d256c2b8380582961fda) Add async infrastructure to core I/O classes and interfaces - [`fcb3838`](https://github.com/adamhathcock/sharpcompress/commit/fcb3838724cc4e7f31ec05763c5b219cb2f344fd) Implement async methods across all Archive entries and extension methods - [`7799d2d`](https://github.com/adamhathcock/sharpcompress/commit/7799d2d5befb31b40817a17453727dfc958b5a7b) Update README and USAGE documentation with async examples - [`999a1eb`](https://github.com/adamhathcock/sharpcompress/commit/999a1eb32760190b66ae74fb64477a57deb5cca7) Add comprehensive async tests demonstrating new functionality - [`1cd2459`](https://github.com/adamhathcock/sharpcompress/commit/1cd24593e99c931742a44d8fe5cc7775abe2a904) Fix test to use deterministic DateTime value per code review ### 📊 Changes **20 files changed** (+1083 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+78 -0) 📝 `USAGE.md` (+143 -0) 📝 `src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs` (+8 -0) 📝 `src/SharpCompress/Archives/IArchiveEntry.cs` (+8 -0) 📝 `src/SharpCompress/Archives/Rar/RarArchiveEntry.cs` (+5 -0) 📝 `src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs` (+5 -0) 📝 `src/SharpCompress/Archives/Tar/TarArchiveEntry.cs` (+5 -0) 📝 `src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs` (+5 -0) 📝 `src/SharpCompress/Common/ExtractionMethods.cs` (+113 -0) 📝 `src/SharpCompress/IO/SharpCompressStream.cs` (+139 -12) 📝 `src/SharpCompress/IO/SourceStream.cs` (+102 -0) 📝 `src/SharpCompress/Readers/AbstractReader.cs` (+38 -0) 📝 `src/SharpCompress/Readers/IReader.cs` (+9 -0) 📝 `src/SharpCompress/Readers/IReaderExtensions.cs` (+62 -0) 📝 `src/SharpCompress/Utility.cs` (+135 -0) 📝 `src/SharpCompress/Writers/AbstractWriter.cs` (+15 -0) 📝 `src/SharpCompress/Writers/IWriter.cs` (+8 -0) 📝 `src/SharpCompress/Writers/IWriterExtensions.cs` (+69 -0) 📝 `src/SharpCompress/packages.lock.json` (+3 -3) ➕ `tests/SharpCompress.Test/AsyncTests.cs` (+133 -0) </details> ### 📄 Description All I/O operations now support async/await with CancellationToken. Methods performing async operations are suffixed with `Async`. ## Changes **Core Infrastructure** - `SharpCompressStream`, `SourceStream` - Added `ReadAsync()`, `WriteAsync()`, `FlushAsync()` - Utility methods - Added `TransferToAsync()`, `SkipAsync()` with CancellationToken support **Public APIs** - `IReader.WriteEntryToAsync()` - Extract entries asynchronously - `IWriter.WriteAsync()` - Write entries asynchronously - `IArchiveEntry.OpenEntryStreamAsync()` - Open entry streams asynchronously **Extension Methods** - `reader.WriteAllToDirectoryAsync()` - Bulk async extraction - `writer.WriteAllAsync()` - Bulk async compression - All methods accept optional `CancellationToken` **Archive Format Support** - All formats (GZip, Tar, Zip, Rar, SevenZip) implement async entry stream opening ## Usage **Async Reading:** ```csharp using var reader = ReaderFactory.Open(stream); await reader.WriteAllToDirectoryAsync(@"C:\output", options, cancellationToken); ``` **Async Writing:** ```csharp using var writer = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate); await writer.WriteAllAsync(@"D:\files", "*", SearchOption.AllDirectories, cancellationToken); ``` **Async Entry Access:** ```csharp using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken); await entryStream.CopyToAsync(outputStream, cancellationToken); ``` ## Compatibility - All synchronous methods remain unchanged - no breaking changes - Framework support: net48, net481, netstandard2.0, net6.0, net8.0 - Older frameworks use Microsoft.Bcl.AsyncInterfaces polyfill (already referenced) ## Documentation - README.md - Added async overview and examples - USAGE.md - Added comprehensive async patterns section - New test file `AsyncTests.cs` with 6 async scenarios <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Convert all Stream access to be async. All IO should go through asynchronous methods now. Methods using async should be renamed to be Async. .NET legacy (.net framework 4.8 and 4.8.1 and .net standard) might need something different. Use compiler flags if necessary. Update the README when done. </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --- <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:20:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1392