[PR #986] [MERGED] Support CompressionType.None for uncompressed 7z files #1403

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/986
Author: @Copilot
Created: 10/27/2025
Status: Merged
Merged: 10/27/2025
Merged by: @adamhathcock

Base: masterHead: copilot/fix-compressiontype-none-bug


📝 Commits (4)

  • fc672da Initial plan
  • 2241e27 Initial exploration: Understanding the issue
  • f869712 Add support for CompressionType.None for uncompressed 7z files
  • 588d176 Final verification - all tests pass

📊 Changes

4 files changed (+24 additions, -3 deletions)

View changed files

📝 src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs (+2 -0)
📝 src/SharpCompress/packages.lock.json (+3 -3)
📝 tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs (+19 -0)
tests/TestArchives/Archives/7Zip.Copy.7z (+0 -0)

📄 Description

Accessing the CompressionType property on entries from uncompressed 7z archives throws InvalidFormatException, despite extraction working correctly.

Changes

  • Added K_COPY constant (0x0) to SevenZipFilePart.cs for uncompressed method ID
  • Updated GetCompression() to return CompressionType.None for K_COPY method
  • Added test coverage with 7Zip.Copy.7z archive and 3 unit tests

Example

using var archive = SevenZipArchive.Open("uncompressed.7z");
foreach (var entry in archive.Entries)
{
    // Previously threw InvalidFormatException
    // Now correctly returns CompressionType.None
    Console.WriteLine(entry.CompressionType);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] CompressionType.None should be supported for uncompressed 7z files</issue_title>
<issue_description># What is the bug?
Uncompressed files within 7z archives already seem to be supported, in that they already "extract" correctly.
However, when reading the CompressionType field within the Entry, it currently throws an InvalidFormatException

Proposed Solution

I believe the fix should be simple enough.
Within the following block,

45de87cb97/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs (L70-L90)

We could add:

private const uint K_COPY = 0x0;

and

K_COPY => CompressionType.None, 

If you agree, I'd be happy to open a pull-request, but I figured I'd open an issue first, in case you have different thoughts.</issue_description>

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

@adamhathcock Please make a PR for this. Seems just overlooked

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


🔄 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/986 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 10/27/2025 **Status:** ✅ Merged **Merged:** 10/27/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `copilot/fix-compressiontype-none-bug` --- ### 📝 Commits (4) - [`fc672da`](https://github.com/adamhathcock/sharpcompress/commit/fc672da0e0ae4725bad07d422d7dc81d1a616b53) Initial plan - [`2241e27`](https://github.com/adamhathcock/sharpcompress/commit/2241e27e686247b703077b8d571346dcac1f2b02) Initial exploration: Understanding the issue - [`f869712`](https://github.com/adamhathcock/sharpcompress/commit/f8697120a009bbb0005cc488a87c88e6e6550214) Add support for CompressionType.None for uncompressed 7z files - [`588d176`](https://github.com/adamhathcock/sharpcompress/commit/588d176b96eae0e28aec74f8703a6c0d4ca3d335) Final verification - all tests pass ### 📊 Changes **4 files changed** (+24 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs` (+2 -0) 📝 `src/SharpCompress/packages.lock.json` (+3 -3) 📝 `tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs` (+19 -0) ➕ `tests/TestArchives/Archives/7Zip.Copy.7z` (+0 -0) </details> ### 📄 Description Accessing the `CompressionType` property on entries from uncompressed 7z archives throws `InvalidFormatException`, despite extraction working correctly. ## Changes - **Added K_COPY constant** (0x0) to `SevenZipFilePart.cs` for uncompressed method ID - **Updated GetCompression()** to return `CompressionType.None` for K_COPY method - **Added test coverage** with `7Zip.Copy.7z` archive and 3 unit tests ## Example ```csharp using var archive = SevenZipArchive.Open("uncompressed.7z"); foreach (var entry in archive.Entries) { // Previously threw InvalidFormatException // Now correctly returns CompressionType.None Console.WriteLine(entry.CompressionType); } ``` <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Bug] CompressionType.None should be supported for uncompressed 7z files</issue_title> > <issue_description># What is the bug? > Uncompressed files within 7z archives already seem to be supported, in that they already "extract" correctly. > However, when reading the CompressionType field within the Entry, it currently throws an **InvalidFormatException** > > # Proposed Solution > I believe the fix should be simple enough. > Within the following block, > > https://github.com/adamhathcock/sharpcompress/blob/45de87cb97ad146a6abf7c66ef65e4226953a00e/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs#L70-L90 > > > We could add: > ```csharp > private const uint K_COPY = 0x0; > ``` > > and > ```csharp > K_COPY => CompressionType.None, > ``` > > ----- > > If you agree, I'd be happy to open a pull-request, but I figured I'd open an issue first, in case you have different thoughts.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > <comment_new><author>@adamhathcock</author><body> > Please make a PR for this. Seems just overlooked</body></comment_new> > </comments> > </details> - Fixes adamhathcock/sharpcompress#944 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --- <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:24 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1403