mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
[PR #1143] Add opt-in multi-threading support for file-based archive extraction #1581
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/adamhathcock/sharpcompress/pull/1143
Author: @Copilot
Created: 1/18/2026
Status: 🔄 Open
Base:
master← Head:copilot/support-multi-threading-path📝 Commits (3)
e0a43e9Initial plan3e23a6eAdd multi-threading support for file-based archives - sync test passing4a6e523Add opt-in multi-threading support with SupportsMultiThreadedExtraction flag📊 Changes
9 files changed (+640 additions, -11 deletions)
View changed files
📝
src/SharpCompress/Archives/AbstractArchive.cs(+13 -0)📝
src/SharpCompress/Archives/IArchive.cs(+8 -0)📝
src/SharpCompress/Archives/Rar/SeekableFilePart.cs(+71 -0)📝
src/SharpCompress/Common/Tar/TarFilePart.cs(+39 -1)📝
src/SharpCompress/Common/Zip/SeekableZipFilePart.cs(+170 -10)📝
src/SharpCompress/IO/SourceStream.cs(+24 -0)📝
src/SharpCompress/Readers/ReaderOptions.cs(+8 -0)➕
tests/SharpCompress.Test/Tar/TarMultiThreadTests.cs(+115 -0)➕
tests/SharpCompress.Test/Zip/ZipMultiThreadTests.cs(+192 -0)📄 Description
When an archive is opened from a
FileInfoor file path, multiple threads can now extract different entries concurrently when explicitly enabled. Previously, all extractions shared a singleFileStream, causing position conflicts and corruption.Changes
Core Infrastructure
SourceStream: AddedCreateIndependentStream(volumeIndex)to create newFileStreaminstances from trackedFileInfoobjectsSemaphoreSlimfor async) to prevent concurrent header load racesOpt-in Multi-threading Support
IArchive.SupportsMultiThreadedExtraction: Boolean property indicating if multi-threaded extraction is supported for the archive instancetruewhen archive is opened from a file, multi-threading is enabled, and archive is not SOLIDReaderOptions.EnableMultiThreadedExtraction: Explicit opt-in flag to enable multi-threaded extraction (defaults tofalsefor backward compatibility)Format Support
Modified entry extraction to create independent streams when file-based and multi-threading is enabled:
SeekableZipFilePart: Both header loading and data extraction use independent streams when flag is enabledTarFilePart: Data extraction uses independent streams when flag is enabledSeekableFilePart(Rar): Data extraction uses independent streams when flag is enabledFallback Behavior
Streaminstead ofFileInfo) continue using shared streams - backward compatible, no multi-threading supportExample Usage
Known Limitations
Testing
Added
ZipMultiThreadTestsandTarMultiThreadTestsdemonstrating concurrent extraction patterns. Tests verify that:SupportsMultiThreadedExtractionproperty accurately reflects multi-threading availability<issue_title>Support multi-threading when supplying a path/FileInfo</issue_title>
><issue_description>Since the ultimate source is a local file, there's no reason multi-threading won't work for some formats. What is required:
>
> - a format that supports header reading separate from bytes or one that can skip entries (e.g. Zip, Rar, Tar)
> - compressed entries can be read from separate parts simultaneously (probably most?)
> - known non-supporting as things are single compressed streams that usually wrap a Tar (Gzip, BZip2, etc)
> - unknown: "SOLID" support. SOLID Rars and 7ZIps compress headers with entry bytes. 7Zip might be able to work but differently. If the entire Rar is SOLID then it's like a Gzipped Tar which can't really work either.</issue_description>
>
><agent_instructions>make sure things are FileInfo and RandomAccess. Allow multiple independent streams to ensure isolation across threads. new streams should probably seek back to the file to get the stream of bytes</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
>
>
Original prompt
💬 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.