[PR #1069] WIP: Implement compressed tar archive support in ArchiveFactory #1492

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

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

State: closed
Merged: No


Users attempting to open tar.bz2/tar.lz archives via ArchiveFactory.Open() received a generic "Cannot determine compressed stream type" error. Per feedback, these formats should be supported directly via ArchiveFactory.Open() for seekable and file streams.

Work In Progress

This PR is implementing full support for compressed tar formats (tar.bz2, tar.lz, tar.xz, tar.zst, etc.) via the Archive API.

Current Implementation

  • Enhanced TarFactory.IsArchive(): Detects compressed tar formats by:

    • Checking for uncompressed tar headers
    • Decompressing stream to check if it contains a tar archive
    • Seeking back to preserve stream position
  • Enhanced TarFactory.Open(): Decompresses compressed tar files to seekable MemoryStream and returns TarArchive

Current Blockers

  • Some compression stream constructors (e.g., LZipStream) don't support leaveOpen parameter
  • Stream disposal during detection phase causes issues with factory identification flow
  • Works when calling TarFactory directly, but fails through ArchiveFactory.FindFactory()

Questions for Review

  1. Should dedicated BZip2Archive and LZipArchive classes be created (similar to GZipArchive)?
  2. Continue with MemoryStream approach and resolve stream disposal issues?
  3. Is there a preferred pattern for handling compression formats that don't support leaveOpen?

Awaiting guidance on preferred architecture approach before completing implementation.


Original Issue: Users trying to decompress tar.bz2 or tar.lz files created with SharpCompress received:

InvalidOperationException: Cannot determine compressed stream type. Supported Archive Formats: Zip, Rar, 7Zip, GZip, Tar
Original prompt

This section details on the original issue you should resolve

<issue_title>Decompress tar.lz tar.bz2 cause exception</issue_title>
<issue_description>I tried to decompress the tar.bz2 or tar.lz that created from the SharpCompress

But unfortunately, I got the exception:
Cannot determine compressed stream type. Supported Archive Formats: Zip, Rar, 7Zip, GZip, Tar

StackTrace:
    at SharpCompress.Archives.ArchiveFactory.FindFactory[T](Stream stream) in /_/src/SharpCompress/Archives/ArchiveFactory.cs:line 164
    at SharpCompress.Archives.ArchiveFactory.Open(Stream stream, ReaderOptions readerOptions) in /_/src/SharpCompress/Archives/ArchiveFactory.cs:line 24
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1069 **State:** closed **Merged:** No --- Users attempting to open tar.bz2/tar.lz archives via `ArchiveFactory.Open()` received a generic "Cannot determine compressed stream type" error. Per feedback, these formats should be supported directly via ArchiveFactory.Open() for seekable and file streams. ## Work In Progress This PR is implementing full support for compressed tar formats (tar.bz2, tar.lz, tar.xz, tar.zst, etc.) via the Archive API. ## Current Implementation - **Enhanced `TarFactory.IsArchive()`**: Detects compressed tar formats by: - Checking for uncompressed tar headers - Decompressing stream to check if it contains a tar archive - Seeking back to preserve stream position - **Enhanced `TarFactory.Open()`**: Decompresses compressed tar files to seekable MemoryStream and returns TarArchive ## Current Blockers - Some compression stream constructors (e.g., LZipStream) don't support `leaveOpen` parameter - Stream disposal during detection phase causes issues with factory identification flow - Works when calling TarFactory directly, but fails through ArchiveFactory.FindFactory() ## Questions for Review 1. Should dedicated BZip2Archive and LZipArchive classes be created (similar to GZipArchive)? 2. Continue with MemoryStream approach and resolve stream disposal issues? 3. Is there a preferred pattern for handling compression formats that don't support leaveOpen? Awaiting guidance on preferred architecture approach before completing implementation. --- **Original Issue**: Users trying to decompress tar.bz2 or tar.lz files created with SharpCompress received: ``` InvalidOperationException: Cannot determine compressed stream type. Supported Archive Formats: Zip, Rar, 7Zip, GZip, Tar ``` <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Decompress tar.lz tar.bz2 cause exception</issue_title> > <issue_description>I tried to decompress the `tar.bz2` or `tar.lz` that created from the SharpCompress > > But unfortunately, I got the exception: > `Cannot determine compressed stream type. Supported Archive Formats: Zip, Rar, 7Zip, GZip, Tar` > > ``` > StackTrace: > at SharpCompress.Archives.ArchiveFactory.FindFactory[T](Stream stream) in /_/src/SharpCompress/Archives/ArchiveFactory.cs:line 164 > at SharpCompress.Archives.ArchiveFactory.Open(Stream stream, ReaderOptions readerOptions) in /_/src/SharpCompress/Archives/ArchiveFactory.cs:line 24 > ```</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes adamhathcock/sharpcompress#1068 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
claunia added the pull-request label 2026-01-29 22:20:50 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1492