Skip to content

Fix GZip write async#1319

Closed
adamhathcock wants to merge 1 commit into
masterfrom
adam/fix-gzip-save
Closed

Fix GZip write async#1319
adamhathcock wants to merge 1 commit into
masterfrom
adam/fix-gzip-save

Conversation

@adamhathcock
Copy link
Copy Markdown
Owner

fixes #1316

This pull request adds asynchronous support for opening entry streams in GZip archive entries and introduces new tests to ensure correct async behavior. The main focus is on enabling async operations for GZip writable archive entries and verifying them with comprehensive test coverage.

Async support for GZip archive entries:

  • Made OpenEntryStreamAsync virtual in GZipArchiveEntry to allow overriding for async stream opening.
  • Added an override for OpenEntryStreamAsync in GZipWritableArchiveEntry that supports cancellation and returns a ValueTask<Stream>.
  • Included necessary System.Threading and System.Threading.Tasks namespaces for async/cancellation support in GZipWritableArchiveEntry.

Test improvements:

  • Added a new async test GZip_Create_New_Async to verify creating, saving, and extracting GZip archives asynchronously, ensuring file integrity.
  • Updated test imports to support new async test scenarios.

Copilot AI review requested due to automatic review settings May 13, 2026 10:34
@adamhathcock
Copy link
Copy Markdown
Owner Author

Wrong branch

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes async save/create behavior for writable GZip archives by enabling writable entries to provide an async-capable entry stream (avoiding the NotImplementedException reported in #1316), and adds an async round-trip test to validate the behavior.

Changes:

  • Made GZipArchiveEntry.OpenEntryStreamAsync virtual so writable entry types can override async stream-opening behavior.
  • Implemented OpenEntryStreamAsync override in GZipWritableArchiveEntry (supports cancellation and returns ValueTask<Stream>).
  • Added a new async test that creates a .gz archive, saves it asynchronously, re-opens it asynchronously, and verifies extracted content integrity.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/SharpCompress.Test/GZip/GZipArchiveAsyncTests.cs Adds an async create/save/open/extract test for GZip archives.
src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs Overrides OpenEntryStreamAsync for writable entries to avoid Parts access and support async save paths.
src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs Makes OpenEntryStreamAsync virtual to allow writable implementations to override.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +207 to +208
await using var archive2 = await GZipArchive.OpenAsyncArchive(
new AsyncOnlyStream(File.OpenRead(filePath))
using SharpCompress.Archives.Tar;
using SharpCompress.Common;
using SharpCompress.Compressors.Deflate;
using SharpCompress.Readers;
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.

GZipArchive.CreateArchiveAsync -> SaveToAsync throws "NotImplementedException"

2 participants