[PR #1092] [CLOSED] Add dual sync/async support for Zip headers and IsArchive async overloads #1521

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1092
Author: @Copilot
Created: 12/30/2025
Status: Closed

Base: masterHead: copilot/add-buffered-stream-async-read


📝 Commits (10+)

  • 7c3c94e Add ArcReaderAsync tests
  • 3bdaba4 fmt
  • fb76bd8 first commit of async reader
  • 1607d27 Merge branch 'master' into adam/async-binary-reader
  • 8415a19 Initial plan
  • af71970 Merge branch 'adam/async-binary-reader' into copilot/add-buffered-stream-async-read
  • 39a0b4c Use BufferedStream for async reading in AsyncBinaryReader
  • ec31cb9 Fix Zip headers to support both sync and async reading
  • 6e0e20b Fix zip64_locator to use ReadUInt32Async instead of ReadUInt16Async
  • 038b9f1 Merge remote-tracking branch 'origin/master' into copilot/add-buffered-stream-async-read

📊 Changes

46 files changed (+1995 additions, -57 deletions)

View changed files

📝 src/SharpCompress/Archives/ArchiveFactory.cs (+126 -0)
📝 src/SharpCompress/Archives/AutoArchiveFactory.cs (+21 -0)
📝 src/SharpCompress/Archives/GZip/GZipArchive.cs (+86 -0)
📝 src/SharpCompress/Archives/IArchiveFactory.cs (+26 -0)
📝 src/SharpCompress/Archives/IMultiArchiveFactory.cs (+26 -0)
📝 src/SharpCompress/Archives/Rar/RarArchive.cs (+66 -0)
📝 src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs (+64 -0)
📝 src/SharpCompress/Archives/Tar/TarArchive.cs (+64 -0)
📝 src/SharpCompress/Archives/Zip/ZipArchive.cs (+154 -2)
src/SharpCompress/Common/AsyncBinaryReader.cs (+117 -0)
📝 src/SharpCompress/Common/FilePart.cs (+6 -0)
📝 src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs (+13 -0)
📝 src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs (+32 -1)
📝 src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs (+3 -0)
📝 src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs (+26 -5)
📝 src/SharpCompress/Common/Zip/Headers/SplitHeader.cs (+4 -0)
📝 src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs (+20 -0)
📝 src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs (+9 -4)
📝 src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs (+24 -10)
📝 src/SharpCompress/Common/Zip/Headers/ZipHeader.cs (+5 -9)

...and 26 more files

📄 Description

Updates all Zip header classes to support both synchronous and asynchronous reading paths while maintaining backward compatibility. Adds async overloads for archive detection methods to enable proper async-only stream support.

Changes Made

Zip Headers - Dual Sync/Async Support

  • Dual abstract methods: Updated ZipHeader base class to define both Read(BinaryReader) and Read(AsyncBinaryReader) abstract methods
  • Full implementation coverage: All Zip header classes now implement both sync and async Read methods (DirectoryEndHeader, DirectoryEntryHeader, LocalEntryHeader, IgnoreHeader, SplitHeader, Zip64DirectoryEndHeader, Zip64DirectoryEndLocatorHeader)
  • Factory classes: ZipHeaderFactory and SeekableZipHeaderFactory provide both sync and async ReadHeader methods
  • Backward compatibility: Existing sync code paths (like ZipArchive.LoadEntries) continue to work unchanged
  • Code reuse: Extracted common processing logic into shared methods to avoid duplication between sync and async implementations

IsArchive Async Overloads

  • Interface extension: Added IsArchiveAsync method to IFactory interface with default implementation
  • Zip archive detection: Added IsZipFileAsync and IsZipMultiAsync methods to ZipArchive for async archive format detection
  • GZip archive detection: Added IsGZipFileAsync method to GZipArchive using ReadFullyAsync utility
  • Factory implementations: ZipFactory and GZipFactory override IsArchiveAsync to use async detection methods
  • Reader factory: Updated ReaderFactory.OpenAsync to call IsArchiveAsync instead of IsArchive for proper async-only stream support

AsyncBinaryReader

  • Simplified implementation: Removed BufferedStream wrapping as it internally uses synchronous Read operations
  • Async-only stream support: Now works correctly with streams that only support async operations
  • Existing buffering: SharpCompressStream already provides buffering with true async support

Test Fixes

  • Test update: Fixed Zip_Reader_Disposal_Test2_Async to use ReaderFactory.OpenAsync
  • TestStream fix: Added ReadAsync overrides to properly forward async calls to underlying stream

Benefits

  • Enables proper async-only stream support for archive detection
  • Reduces system calls during async read operations
  • Improves performance for small reads (bytes, uint16, uint32, etc.)
  • Maintains full backward compatibility with synchronous code paths
  • Enables future async optimization while preserving sync compatibility

The implementation provides true async support for Zip and GZip archive detection and reading, allowing the use of async-only streams throughout the library while maintaining full backward compatibility with synchronous code paths.

Original prompt

Use a buffered stream that reads async from the stream. Consider streams already implemented

The user has attached the following file paths as relevant context:

  • src/SharpCompress/Common/AsyncBinaryReader.cs

Created from VS Code.


💬 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/1092 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 12/30/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `copilot/add-buffered-stream-async-read` --- ### 📝 Commits (10+) - [`7c3c94e`](https://github.com/adamhathcock/sharpcompress/commit/7c3c94ed7f534838d5ab6c2049a2233ca26c2b69) Add ArcReaderAsync tests - [`3bdaba4`](https://github.com/adamhathcock/sharpcompress/commit/3bdaba46a91de3131ce443d87289e7d6b7ab48cb) fmt - [`fb76bd8`](https://github.com/adamhathcock/sharpcompress/commit/fb76bd82f2d9cde7ecc54a28b1739fa52929cf7f) first commit of async reader - [`1607d27`](https://github.com/adamhathcock/sharpcompress/commit/1607d2768e39654cb80d3655d6a7b9323cab8e72) Merge branch 'master' into adam/async-binary-reader - [`8415a19`](https://github.com/adamhathcock/sharpcompress/commit/8415a19912bd4f40c27d7118e4222cded707c02d) Initial plan - [`af71970`](https://github.com/adamhathcock/sharpcompress/commit/af719707bfc1ad3e67422f21e2b14e157d9cc71e) Merge branch 'adam/async-binary-reader' into copilot/add-buffered-stream-async-read - [`39a0b4c`](https://github.com/adamhathcock/sharpcompress/commit/39a0b4ce78fb57296eb4c3f6f945ab6b5b44191c) Use BufferedStream for async reading in AsyncBinaryReader - [`ec31cb9`](https://github.com/adamhathcock/sharpcompress/commit/ec31cb9987e44cf1fac2393447b5c1b4f01b4585) Fix Zip headers to support both sync and async reading - [`6e0e20b`](https://github.com/adamhathcock/sharpcompress/commit/6e0e20ba6ea53d7fa0117f4aebdbd13741862994) Fix zip64_locator to use ReadUInt32Async instead of ReadUInt16Async - [`038b9f1`](https://github.com/adamhathcock/sharpcompress/commit/038b9f18c6af57d6ba141dc4a3d87fd9c91cbe03) Merge remote-tracking branch 'origin/master' into copilot/add-buffered-stream-async-read ### 📊 Changes **46 files changed** (+1995 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/ArchiveFactory.cs` (+126 -0) 📝 `src/SharpCompress/Archives/AutoArchiveFactory.cs` (+21 -0) 📝 `src/SharpCompress/Archives/GZip/GZipArchive.cs` (+86 -0) 📝 `src/SharpCompress/Archives/IArchiveFactory.cs` (+26 -0) 📝 `src/SharpCompress/Archives/IMultiArchiveFactory.cs` (+26 -0) 📝 `src/SharpCompress/Archives/Rar/RarArchive.cs` (+66 -0) 📝 `src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs` (+64 -0) 📝 `src/SharpCompress/Archives/Tar/TarArchive.cs` (+64 -0) 📝 `src/SharpCompress/Archives/Zip/ZipArchive.cs` (+154 -2) ➕ `src/SharpCompress/Common/AsyncBinaryReader.cs` (+117 -0) 📝 `src/SharpCompress/Common/FilePart.cs` (+6 -0) 📝 `src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs` (+13 -0) 📝 `src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs` (+32 -1) 📝 `src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs` (+3 -0) 📝 `src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs` (+26 -5) 📝 `src/SharpCompress/Common/Zip/Headers/SplitHeader.cs` (+4 -0) 📝 `src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs` (+20 -0) 📝 `src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs` (+9 -4) 📝 `src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs` (+24 -10) 📝 `src/SharpCompress/Common/Zip/Headers/ZipHeader.cs` (+5 -9) _...and 26 more files_ </details> ### 📄 Description Updates all Zip header classes to support both synchronous and asynchronous reading paths while maintaining backward compatibility. Adds async overloads for archive detection methods to enable proper async-only stream support. ## Changes Made ### Zip Headers - Dual Sync/Async Support - **Dual abstract methods**: Updated `ZipHeader` base class to define both `Read(BinaryReader)` and `Read(AsyncBinaryReader)` abstract methods - **Full implementation coverage**: All Zip header classes now implement both sync and async Read methods (DirectoryEndHeader, DirectoryEntryHeader, LocalEntryHeader, IgnoreHeader, SplitHeader, Zip64DirectoryEndHeader, Zip64DirectoryEndLocatorHeader) - **Factory classes**: `ZipHeaderFactory` and `SeekableZipHeaderFactory` provide both sync and async `ReadHeader` methods - **Backward compatibility**: Existing sync code paths (like `ZipArchive.LoadEntries`) continue to work unchanged - **Code reuse**: Extracted common processing logic into shared methods to avoid duplication between sync and async implementations ### IsArchive Async Overloads - **Interface extension**: Added `IsArchiveAsync` method to `IFactory` interface with default implementation - **Zip archive detection**: Added `IsZipFileAsync` and `IsZipMultiAsync` methods to `ZipArchive` for async archive format detection - **GZip archive detection**: Added `IsGZipFileAsync` method to `GZipArchive` using `ReadFullyAsync` utility - **Factory implementations**: `ZipFactory` and `GZipFactory` override `IsArchiveAsync` to use async detection methods - **Reader factory**: Updated `ReaderFactory.OpenAsync` to call `IsArchiveAsync` instead of `IsArchive` for proper async-only stream support ### AsyncBinaryReader - **Simplified implementation**: Removed BufferedStream wrapping as it internally uses synchronous Read operations - **Async-only stream support**: Now works correctly with streams that only support async operations - **Existing buffering**: SharpCompressStream already provides buffering with true async support ### Test Fixes - **Test update**: Fixed `Zip_Reader_Disposal_Test2_Async` to use `ReaderFactory.OpenAsync` - **TestStream fix**: Added `ReadAsync` overrides to properly forward async calls to underlying stream ## Benefits - Enables proper async-only stream support for archive detection - Reduces system calls during async read operations - Improves performance for small reads (bytes, uint16, uint32, etc.) - Maintains full backward compatibility with synchronous code paths - Enables future async optimization while preserving sync compatibility The implementation provides true async support for Zip and GZip archive detection and reading, allowing the use of async-only streams throughout the library while maintaining full backward compatibility with synchronous code paths. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Use a buffered stream that reads async from the stream. Consider streams already implemented > > The user has attached the following file paths as relevant context: > - src/SharpCompress/Common/AsyncBinaryReader.cs </details> <!-- START COPILOT CODING AGENT SUFFIX --> Created from [VS Code](https://code.visualstudio.com/docs/copilot/copilot-coding-agent). <!-- 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:57 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1521