[PR #1132] Clean up for async creation #1567

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

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

State: closed
Merged: Yes


For some formats, async should be all the way. 7Zip needs fixing

This pull request introduces asynchronous detection methods for multiple archive and compression formats, allowing non-blocking checks to determine file types. It also refactors and simplifies some synchronous detection logic for improved performance and consistency. The most significant changes are grouped below:

Asynchronous Format Detection:

  • Added IsArchiveAsync or similar async methods for ACE (AceHeader.cs), ARJ (ArjHeader.cs), BZip2 (BZip2Stream.cs), LZip (LZipStream.cs), LZW (LzwStream.cs), ZStandard (ZStandardStream.cs), RAR (RarArchive.Factory.cs), SevenZip (SevenZipArchive.Factory.cs), TAR (TarArchive.Factory.cs), and XZ (XZStream.cs) formats, enabling asynchronous file type checks with CancellationToken support. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

  • Updated the ACE and ARJ factories to implement and expose these new asynchronous detection methods. [1] [2]

Synchronous Detection Refactoring & Performance:

  • Refactored synchronous detection logic to use pooled buffers (via ArrayPool<byte>.Shared) for ARC and SevenZip formats, reducing allocations and improving performance. [1] [2]

API Consistency and Interface Changes:

  • Removed the CancellationToken parameter from the IArchiveFactory.OpenAsyncArchive method and its implementations to simplify the API, as the token was not being used in actual asynchronous operations. [1] [2] [3]

General Codebase Improvements:

  • Added missing using directives for System.Threading and System.Threading.Tasks where needed to support the new asynchronous methods. [1] [2] [3] [4] [5] [6] [7]

These changes collectively modernize the archive/compression format detection APIs and improve their efficiency and usability.

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1132 **State:** closed **Merged:** Yes --- For some formats, async should be all the way. 7Zip needs fixing This pull request introduces asynchronous detection methods for multiple archive and compression formats, allowing non-blocking checks to determine file types. It also refactors and simplifies some synchronous detection logic for improved performance and consistency. The most significant changes are grouped below: **Asynchronous Format Detection:** * Added `IsArchiveAsync` or similar async methods for ACE (`AceHeader.cs`), ARJ (`ArjHeader.cs`), BZip2 (`BZip2Stream.cs`), LZip (`LZipStream.cs`), LZW (`LzwStream.cs`), ZStandard (`ZStandardStream.cs`), RAR (`RarArchive.Factory.cs`), SevenZip (`SevenZipArchive.Factory.cs`), TAR (`TarArchive.Factory.cs`), and XZ (`XZStream.cs`) formats, enabling asynchronous file type checks with `CancellationToken` support. [[1]](diffhunk://#diff-33cc7b6697bb02c3e838edce251357c47d0e9e74e66e026ddcf3bd33377843f0R110-R129) [[2]](diffhunk://#diff-6f8a0d963a0c12fc7d1746934ec553bc4f163d1e7204d8276899fb3e1b2e6a5aR153-R172) [[3]](diffhunk://#diff-b4cbaaf64addd2a93675e79bf84d7840214f73a08d6c5638ccfbc0124fbe2ea1R152-R172) [[4]](diffhunk://#diff-44b45464653f8440fd0885412f8b8b22fdc507753278d389bd5b3b6b05a7a32cR225-R237) [[5]](diffhunk://#diff-74d195a64f0d55f0eec9f7b618e60241d5b1aa571c50a89d1b75444f0ca50cb8R100-R138) [[6]](diffhunk://#diff-51cd971e36b7f18e787302b135cacae4f9ebf87194d00f580121466aba16b585R47-R67) [[7]](diffhunk://#diff-c917224df3ff936ef99480cb13f4d79d64db4bac3abba0c377b716a24c209c69R167-R184) [[8]](diffhunk://#diff-3c93be69c25d07fa44b4fe2394bb54f93c4e63e05e387b7bd6d5713048d44d01L160-R208) [[9]](diffhunk://#diff-31112d7dfdc65bd7cca0da2d515de9d2b599c9a3196bc3562031d6e6a59788e3R168-R188) [[10]](diffhunk://#diff-ac3f8a33f27e97f618b5177fa107cdb4e26e43031510a9896223d8f67a83418eR63-R78) * Updated the ACE and ARJ factories to implement and expose these new asynchronous detection methods. [[1]](diffhunk://#diff-ed73ecc9390f716d464db47b9348155cd299e896469da34e16fdfa2ecd1aa47bR32-R38) [[2]](diffhunk://#diff-ed73ecc9390f716d464db47b9348155cd299e896469da34e16fdfa2ecd1aa47bL44-L49) **Synchronous Detection Refactoring & Performance:** * Refactored synchronous detection logic to use pooled buffers (via `ArrayPool<byte>.Shared`) for ARC and SevenZip formats, reducing allocations and improving performance. [[1]](diffhunk://#diff-800f1b0c584eba50b849faa713b1d38c49e98276a9c84787069a948f58d85606L39-R49) [[2]](diffhunk://#diff-3c93be69c25d07fa44b4fe2394bb54f93c4e63e05e387b7bd6d5713048d44d01L160-R208) **API Consistency and Interface Changes:** * Removed the `CancellationToken` parameter from the `IArchiveFactory.OpenAsyncArchive` method and its implementations to simplify the API, as the token was not being used in actual asynchronous operations. [[1]](diffhunk://#diff-4b08b3148476395372bc9e8bba6bebb7a72acfa5050129dc7a663e1006cbcbefL50-R50) [[2]](diffhunk://#diff-14afa030115e58257f705ec89e4ff1f3f81c9faa64fc5c1ae6f4ec1671f6c0f6L43-R44) [[3]](diffhunk://#diff-22b8bc5a3d713f2404d058a5fddfba4cec7f175d67a00be88fe4f96da36f7d18L81-R81) **General Codebase Improvements:** * Added missing `using` directives for `System.Threading` and `System.Threading.Tasks` where needed to support the new asynchronous methods. [[1]](diffhunk://#diff-33cc7b6697bb02c3e838edce251357c47d0e9e74e66e026ddcf3bd33377843f0R3-R4) [[2]](diffhunk://#diff-6f8a0d963a0c12fc7d1746934ec553bc4f163d1e7204d8276899fb3e1b2e6a5aR6) [[3]](diffhunk://#diff-51cd971e36b7f18e787302b135cacae4f9ebf87194d00f580121466aba16b585R6) [[4]](diffhunk://#diff-74d195a64f0d55f0eec9f7b618e60241d5b1aa571c50a89d1b75444f0ca50cb8R3-R4) [[5]](diffhunk://#diff-3c93be69c25d07fa44b4fe2394bb54f93c4e63e05e387b7bd6d5713048d44d01R2-L9) [[6]](diffhunk://#diff-800f1b0c584eba50b849faa713b1d38c49e98276a9c84787069a948f58d85606R2) [[7]](diffhunk://#diff-c917224df3ff936ef99480cb13f4d79d64db4bac3abba0c377b716a24c209c69R6) These changes collectively modernize the archive/compression format detection APIs and improve their efficiency and usability.
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#1567