Skip to content

Change interfaces to be consistent for new Async paths (definitely breaks things)#1128

Merged
adamhathcock merged 38 commits intomasterfrom
adam/async-interface
Jan 15, 2026
Merged

Change interfaces to be consistent for new Async paths (definitely breaks things)#1128
adamhathcock merged 38 commits intomasterfrom
adam/async-interface

Conversation

@adamhathcock
Copy link
Owner

@adamhathcock adamhathcock commented Jan 12, 2026

API thinking here: #1129

This pull request introduces several improvements and clarifications to the SharpCompress codebase and documentation, focusing on enhancing async support, updating documentation for modern usage, and cleaning up code and configuration files. The most significant changes are grouped and summarized below.

Async API Enhancements and Consistency:

  • Improved async method implementations in AbstractArchive by using explicit async enumerator methods for casting and updating aggregate operations to use their async variants (e.g., AggregateAsync, AllAsync). Also added TotalUncompressedSizeAsync and clarified IsEncryptedAsync return type. [1] [2]
  • Refactored ArchiveFactory async methods to remove unnecessary ConfigureAwait(false), streamline calls, and eliminate redundant XML documentation comments, making the async API more idiomatic and easier to maintain. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated AbstractWritableArchive to implement the new IWritableAsyncArchive interface and unified interface method implementations under IWritableArchiveCommon, improving consistency for writable archives. [1] [2]

Documentation Updates and Modernization:

  • Overhauled docs/API.md to reflect modern async usage patterns, clarify types (IEntryIArchiveEntry), provide more accurate code samples, and expand on supported compression and archive types. Also updated extraction and writer usage to reflect best practices and new APIs. [1] [2] [3] [4] [5] [6] [7]

Configuration and Project Maintenance:

  • Added Microsoft.NET.ILLink.Task package to central package management and enabled CentralPackageTransitivePinningEnabled in build properties to improve dependency management. [1] [2]
  • Removed the .editorconfig rule that set CS1998 (async method lacks 'await') as an error, likely to reduce noise for intentionally synchronous async methods.
  • Updated the solution file to add .gitignore and remove obsolete documentation files, reflecting a cleanup of project structure.

Minor Documentation and Typo Fixes:

  • Fixed a typo in the property name (TotalUncompressSizeTotalUncompressedSize) for clarity and consistency.
  • Removed an outdated note about multi-framework differences from AGENTS.md.

Change return types from ValueTask<T> to direct interface types (IAsyncArchive, IAsyncReader, IWriter) for wrapper methods that don't perform async work. This eliminates unnecessary async state machine allocations while maintaining the same public API behavior.

Changes:
- Interface definitions: Updated IArchiveFactory, IMultiArchiveFactory, IReaderFactory, IWriterFactory
- Concrete factories: Updated archive factories (Zip, Tar, Rar, GZip, SevenZip) and reader-only factories (Ace, Arc, Arj)
- Static factory methods: Updated ReaderFactory, ArchiveFactory, WriterFactory to use new signatures
- Archive classes: Updated static OpenAsync methods in ZipArchive, TarArchive, RarArchive, SevenZipArchive, GZipArchive
- Supporting changes: Updated Factory.cs and async polyfills

Performance benefit: Reduced GC pressure by eliminating unnecessary state machine overhead for non-async wrapper methods.
…y.OpenAsync and use IAsyncReader

- Removed 'await' keyword before ReaderFactory.OpenAsync() calls since the method returns IAsyncReader directly (not Task)
- Changed ZipReader.Open() to ReaderFactory.OpenAsync() in Zip64AsyncTests.ReadForwardOnlyAsync()
- Changed TarReader.Open() to ReaderFactory.OpenAsync() in TarReaderAsyncTests.Tar_BZip2_Entry_Stream_Async()
- Fixed EntryStream disposal from 'await using' to 'using' since EntryStream doesn't implement IAsyncDisposable
- These changes fix compilation errors where async methods were being called on IReader (synchronous) instead of IAsyncReader (asynchronous)
Copilot AI review requested due to automatic review settings January 12, 2026 15:04
@adamhathcock adamhathcock marked this pull request as draft January 12, 2026 15:04
Copy link
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;

using var writer = WriterFactory.Open(stream, _type, writerOptions);
using var writer = WriterFactory.OpenAsync(stream, _type, writerOptions);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The WriterFactory.OpenAsync methods now return IAsyncWriter instead of ValueTask, but they're being used without await. This is inconsistent with the documented async pattern. The tests are calling WriterFactory.OpenAsync() synchronously when they should either await it or use WriterFactory.Open() for synchronous operations.

Copilot uses AI. Check for mistakes.
readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;

await using var reader = await ReaderFactory.OpenAsync(
await using var reader = ReaderFactory.OpenAsync(
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

ReaderFactory.OpenAsync() is being called without await, but the method returns IAsyncReader synchronously (not a Task). This is inconsistent with typical async method patterns. The change makes OpenAsync effectively synchronous, which is confusing naming. Either the method should be renamed to Open() for sync usage, or it should return a Task/ValueTask and be awaited.

Copilot uses AI. Check for mistakes.
{
using Stream stream = File.OpenWrite(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"));
using var writer = WriterFactory.Open(stream, ArchiveType.GZip, CompressionType.BZip2);
using var writer = WriterFactory.Open(
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The Open() method is being used instead of the async equivalent, but this is in an async test method. For consistency with the async test pattern and to properly test async paths, this should use OpenAsync instead.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 15, 2026 13:04
Copy link
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

Copilot reviewed 133 out of 134 changed files in this pull request and generated 11 comments.


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

Comment on lines +157 to +159
public static async IAsyncEnumerable<TResult> CastAsync<TResult>(
this IAsyncEnumerable<object?> source
)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The method is named CastAsync but should follow the extension naming pattern used elsewhere in the file (e.g., it's defined outside the extension blocks). Consider moving this inside an extension block or renaming for consistency.

Copilot uses AI. Check for mistakes.

private static bool SignatureMatch(Stream stream)
{
var reader = new BinaryReader(stream);
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Disposable 'BinaryReader' is created but not disposed.

Copilot uses AI. Check for mistakes.
&& Enum.IsDefined(typeof(EntryType), tarHeader.EntryType);
return readSucceeded || isEmptyArchive;
}
catch { }
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Poor error handling: empty catch block.

Copilot uses AI. Check for mistakes.
@adamhathcock
Copy link
Owner Author

This is known to be imperfect for asynchronous work but it's on it's way

@adamhathcock adamhathcock merged commit 5e90cfd into master Jan 15, 2026
5 checks passed
@adamhathcock adamhathcock deleted the adam/async-interface branch January 15, 2026 15:13
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.

1 participant

Comments