Skip to content

Remove compressed tar archive#1360

Merged
adamhathcock merged 4 commits into
masterfrom
adam/remove-compressed-tar-archive
Jul 12, 2026
Merged

Remove compressed tar archive#1360
adamhathcock merged 4 commits into
masterfrom
adam/remove-compressed-tar-archive

Conversation

@adamhathcock

Copy link
Copy Markdown
Owner

This pull request refines and clarifies the handling of compressed tar files in both the implementation and documentation. The main change is that compressed tar wrappers (like .tar.gz, .tar.bz2, etc.) are now supported only through the TarReader API, not TarArchive or ArchiveFactory. Attempts to open compressed tar files as archives will now be blocked and validated as errors. Documentation and code have been updated to reflect this behavior and to make the distinction between archive and reader APIs much clearer.

API and Implementation changes:

  • TarArchive.OpenArchive and related methods now validate that input streams are raw tar files, not compressed tar wrappers, and throw an error otherwise (src/SharpCompress/Archives/Tar/TarArchive.Factory.cs). [1] [2]
  • Asynchronous and synchronous archive open methods no longer attempt to detect or handle compression wrappers; they require raw tar input only (src/SharpCompress/Archives/Tar/TarArchive.Factory.cs, src/SharpCompress/Archives/Tar/TarArchive.Async.cs). [1] [2] [3] [4] [5] [6]
  • Reader APIs (TarReader) remain the way to access compressed tar files, and related detection logic is clarified. [1] [2]

Documentation updates:

  • All documentation files (docs/TAR_SPEC.md, docs/FORMATS.md, .agents/skills/tar-format/references/tar-format.md, docs/API.md) have been updated to clearly state that compressed tar wrappers are reader-only and cannot be opened as archives. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Code cleanup:

  • Removed unnecessary using statements from TarArchive.cs.

These changes ensure that the distinction between archive and reader APIs is enforced in both the code and documentation, preventing incorrect usage and making the supported scenarios explicit.

Copilot AI review requested due to automatic review settings June 28, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens SharpCompress’s TAR API boundaries by enforcing that compressed tar wrappers (e.g., .tar.gz, .tar.bz2, .tar.xz, .tar.Z) are reader-only (TarReader / ReaderFactory) and can no longer be opened via the archive/random-access APIs (TarArchive / ArchiveFactory), with corresponding documentation updates.

Changes:

  • TarArchive open paths now validate inputs as raw tar only and reject compressed wrappers.
  • TarFactory archive detection is simplified to raw-tar probing; reader paths add TryOpenReader helpers.
  • Tests and docs updated to assert/describe the new “compressed tar = reader-only” contract.

Review findings (blocking):

  • src/SharpCompress/Factories/TarFactory.cs: the method ending at line ~367 now throws InvalidFormatException("Not a tar file.") where it previously fell back to opening a plain tar reader:
    • This strongly suggests raw tar may no longer be openable via the async reader factory path when no wrapper matches (regression vs the removed fallback).
    • Proposed fix (restore the previous fallback behavior in that code path): reintroduce the two removed lines:
      • sharpCompressStream.Rewind();
      • return (IAsyncReader)TarReader.OpenReader(sharpCompressStream, options);
  • src/SharpCompress/Archives/Tar/TarArchive.Factory.cs: EnsureRawTarFile / EnsureRawTarFileAsync unconditionally call stream.Seek(0, ...). If a caller passes a non-seekable stream, this will likely throw NotSupportedException instead of the documented/expected argument validation behavior for TarArchive.OpenArchive(Stream) (seekable requirement). Consider an explicit if (!stream.CanSeek) throw new ArgumentException(...); before seeking.
  • src/SharpCompress/Factories/TarFactory.cs: IsArchive(...) / IsArchiveAsync(...) now directly call TarArchive.IsTarFile(...) on the provided stream. If IsTarFile advances the stream (typical for header probing), this can create observable side-effects for callers expecting stream position to be preserved. Consider saving/restoring position when CanSeek, or ensuring the caller always wraps with a rewindable SharpCompressStream.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/SharpCompress.Test/Tar/TarArchiveTests.cs Adds explicit rejection tests for compressed tar wrappers via ArchiveFactory and TarArchive.
tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs Adds async rejection tests for compressed tar wrappers.
tests/SharpCompress.Test/CompressionProviderTests.cs Updates provider tests to validate decompression via TarReader rather than TarArchive.
tests/SharpCompress.Test/ArchiveFactoryTests.cs Removes compressed-tar from “archive” test cases and adds explicit “not an archive” assertions for compressed tar.
src/SharpCompress/Factories/TarFactory.cs Simplifies raw tar archive detection; introduces TryOpenReader helpers; adjusts async reader open behavior (potential regression).
src/SharpCompress/Archives/Tar/TarArchive.Factory.cs Enforces raw-tar validation for TarArchive open methods via EnsureRawTarFile*.
src/SharpCompress/Archives/Tar/TarArchive.cs Removes wrapper decompression support from TarArchive entry loading paths.
src/SharpCompress/Archives/Tar/TarArchive.Async.cs Mirrors sync changes: no wrapper decompression and always seekable-mode parsing.
docs/TAR_SPEC.md Documents “compressed tar wrappers are reader-only” and updates detection notes accordingly.
docs/FORMATS.md Updates format support matrix to mark compressed tar wrappers as reader-only (no archive API).
docs/API.md Clarifies that compressed tar wrappers are reader-only and not returned by GetArchiveInformation.
.agents/skills/tar-format/references/tar-format.md Updates tar wrapper table and archive vs reader guidance to match the new behavior.

Copilot AI review requested due to automatic review settings July 12, 2026 10:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 12, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 20 out of 20 changed files in this pull request and generated no new comments.

This was referenced Jul 14, 2026
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.

2 participants