Skip to content

Change and clean up options#1193

Merged
adamhathcock merged 19 commits intomasterfrom
adam/cleanup-options
Feb 10, 2026
Merged

Change and clean up options#1193
adamhathcock merged 19 commits intomasterfrom
adam/cleanup-options

Conversation

@adamhathcock
Copy link
Owner

also includes #1191

This pull request makes several important changes to the archive handling interfaces and implementations, focusing on improving option handling and simplifying extraction APIs. The most significant changes are the transition from WriterOptions to the more general IWriterOptions interface, the propagation of ReaderOptions throughout archive classes, and the removal of redundant extraction option parameters from various methods.

Option Handling Improvements

  • Changed all archive saving methods to accept IWriterOptions instead of WriterOptions, allowing for more flexible and extensible writer configuration across archive types. This affects interfaces and implementations in AbstractWritableArchive, GZipArchive, and related async methods. [1] [2] [3] [4] [5]
  • Updated GZip archive writer instantiation to support both direct GZipWriterOptions and conversion from generic IWriterOptions, improving compatibility and extensibility. [1] [2]

Reader Options Propagation

  • Made ReaderOptions a public property on AbstractArchive and added it to the IArchive interface, ensuring consistent access to reader configuration throughout the archive API. [1] [2]
  • Propagated ReaderOptions to GZipArchiveEntry and writable entry constructors, ensuring entries have access to archive-level reader settings. [1] [2]
  • Updated entry loading in GZip archives to pass ReaderOptions to entry constructors, maintaining consistent option usage. [1] [2]

Extraction API Simplification

  • Removed the ExtractionOptions parameter from WriteToDirectory, WriteToFile, and related async methods in IArchiveEntryExtensions, IArchiveExtensions, and IAsyncArchiveExtensions, streamlining the API and reducing unnecessary complexity. [1] [2] [3] [4] [5] [6] [7]
  • Updated ArchiveFactory.WriteToDirectory to use ReaderOptions instead of ExtractionOptions, reflecting the new option handling approach.

General Codebase Updates

  • Added SharpCompress.Common.Options namespace imports to relevant files to support the new option interfaces and types. [1] [2] [3] [4] [5] [6]

These changes collectively enhance the flexibility of archive option handling, simplify extraction APIs, and ensure consistent propagation of reader and writer options throughout the codebase.

adamhathcock and others added 13 commits February 6, 2026 15:16
- Set default ExtractFullPath=true in WriteToDirectoryInternal methods
- Add test case with sample RAR archive containing subdirectories
- Tests verify files are extracted to correct subdirectories, not root

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 9, 2026 17:37
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 9, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 2
Issue Details (click to expand)

SUGGESTION

File Line Issue
src/SharpCompress/Writers/WriterOptions.cs 14 XML doc example uses CompressionType.Zip but should use CompressionType.Deflate
src/SharpCompress/Writers/Zip/ZipWriterOptions.cs 16 XML doc example uses CompressionType.Zip but should use CompressionType.Deflate
Other Observations (not in diff)

No additional issues found in unchanged code.

Files Reviewed (30+ files)
  • src/SharpCompress/Archives/AbstractWritableArchive.cs
  • src/SharpCompress/Archives/AbstractWritableArchive.Async.cs
  • src/SharpCompress/Archives/GZip/GZipArchive.cs
  • src/SharpCompress/Archives/GZip/GZipArchive.Async.cs
  • src/SharpCompress/Archives/IArchive.cs
  • src/SharpCompress/Archives/IArchiveExtensions.cs
  • src/SharpCompress/Archives/IArchiveEntryExtensions.cs
  • src/SharpCompress/Archives/IWritableArchive.cs
  • src/SharpCompress/Factories/GZipFactory.cs
  • src/SharpCompress/Factories/TarFactory.cs
  • src/SharpCompress/Factories/ZipFactory.cs
  • src/SharpCompress/Readers/ReaderOptions.cs
  • src/SharpCompress/Readers/IReaderExtensions.cs
  • src/SharpCompress/Readers/ReaderOptionsExtensions.cs
  • src/SharpCompress/Writers/WriterOptions.cs
  • src/SharpCompress/Writers/Zip/ZipWriterOptions.cs
  • src/SharpCompress/Writers/Tar/TarWriterOptions.cs
  • src/SharpCompress/Writers/GZip/GZipWriterOptions.cs
  • docs/API.md
  • docs/ARCHITECTURE.md
  • docs/ENCODING.md
  • Multiple test files

Fix these issues in Kilo Cloud

Copy link
Contributor

Copilot AI left a comment

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 refactors option handling across SharpCompress by introducing option interfaces (IWriterOptions/IReaderOptions), propagating ReaderOptions through archives/entries, and simplifying extraction APIs by removing per-call ExtractionOptions parameters in favor of archive/reader-level options. It also incorporates the extraction default behavior fix from the linked PR (preserving directory structure when options are omitted) and updates tests accordingly.

Changes:

  • Replace WriterOptions parameters with IWriterOptions across writer factories/archives and update concrete writer option types to records.
  • Make ReaderOptions available via IArchive.ReaderOptions and propagate reader options into entry instances for extraction behavior.
  • Remove ExtractionOptions parameters from extraction helpers/extensions and update tests + add RAR regression tests for subdirectory extraction.

Reviewed changes

Copilot reviewed 105 out of 106 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/SharpCompress.Test/Zip/ZipReaderTests.cs Update reader extraction calls to new extraction API (no ExtractionOptions).
tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs Update async reader extraction calls to new extraction API (no ExtractionOptions).
tests/SharpCompress.Test/Zip/ZipArchiveTests.cs Update archive save/extract usages to pass WriterOptions objects and simplified extraction APIs.
tests/SharpCompress.Test/Zip/ZipArchiveDirectoryTests.cs Update SaveTo calls to use WriterOptions.
tests/SharpCompress.Test/Zip/ZipArchiveAsyncTests.cs Update async archive save/extract calls to simplified APIs and writer options objects.
tests/SharpCompress.Test/Zip/Zip64VersionConsistencyTests.cs Update writer options construction style for new options model.
tests/SharpCompress.Test/WriterTests.cs Update WriteAllToDirectory* calls to simplified extraction API.
tests/SharpCompress.Test/Tar/TarReaderTests.cs Update extraction calls to simplified reader extension API.
tests/SharpCompress.Test/Tar/TarReaderAsyncTests.cs Update async extraction calls to simplified reader extension API.
tests/SharpCompress.Test/Tar/TarArchiveTests.cs Update writer creation and tar writer option initialization to new options model.
tests/SharpCompress.Test/Tar/TarArchiveDirectoryTests.cs Update tar SaveTo calls to use WriterOptions.
tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs Update async tar writer option initialization to new options model.
tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs Update extraction call to simplified reader extension API.
tests/SharpCompress.Test/ReaderTests.cs Update ReaderOptions usage to record with expressions.
tests/SharpCompress.Test/Rar/RarReaderTests.cs Update extraction calls to simplified reader extension API.
tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs Update async extraction calls to simplified reader extension API.
tests/SharpCompress.Test/Rar/RarArchiveTests.cs Update extraction calls and add regression test verifying subdirectory extraction behavior.
tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs Update async extraction calls and add async regression test for subdirectory extraction.
tests/SharpCompress.Test/GZip/GZipWriterTests.cs Update writer factory calls to pass WriterOptions instead of raw CompressionType.
tests/SharpCompress.Test/GZip/GZipWriterAsyncTests.cs Update async writer factory calls to pass WriterOptions.
tests/SharpCompress.Test/GZip/AsyncTests.cs Update async extraction calls to simplified API (no ExtractionOptions).
tests/SharpCompress.Test/ExtractionTests.cs Update zip writer creation to new writer options API; keep traversal/casing extraction assertions.
tests/SharpCompress.Test/ExtractAllEntriesTests.cs Update extraction calls to simplified reader extension API.
tests/SharpCompress.Test/ExtractAll.cs Update archive extraction calls to simplified API (no ExtractionOptions).
tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs Update async extraction calls to simplified API.
tests/SharpCompress.Test/ArchiveTests.cs Update entry extraction calls and writer creation helpers to new options model.
tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs Update async extraction calls to simplified API.
src/SharpCompress/packages.lock.json Update locked SDK-provided package resolutions (ILLink.Tasks versions for net8/net10).
src/SharpCompress/Writers/Zip/ZipWriterOptions.cs Convert zip writer options to record implementing IWriterOptions and add conversion helpers.
src/SharpCompress/Writers/WriterOptions.cs Convert base writer options to record implementing IWriterOptions and add constructors/implicit conversion.
src/SharpCompress/Writers/WriterFactory.cs Change writer factory APIs to accept IWriterOptions.
src/SharpCompress/Writers/Tar/TarWriterOptions.cs Convert tar writer options to record implementing IWriterOptions and add conversion helpers.
src/SharpCompress/Writers/IWriterOpenable.cs Update generic constraint from WriterOptions to IWriterOptions.
src/SharpCompress/Writers/IWriterFactory.cs Update factory interface to accept IWriterOptions.
src/SharpCompress/Writers/GZip/GZipWriterOptions.cs Convert gzip writer options to record implementing IWriterOptions and add conversion helpers.
src/SharpCompress/Writers/AbstractWriter.cs Update writer base type to store IWriterOptions.
src/SharpCompress/Readers/Zip/ZipReader.cs Propagate ReaderOptions (Options) into created ZipEntry instances.
src/SharpCompress/Readers/Zip/ZipReader.Async.cs Propagate ReaderOptions into async-created ZipEntry instances.
src/SharpCompress/Readers/Tar/TarReader.cs Pass reader options through tar entry enumeration.
src/SharpCompress/Readers/Tar/TarReader.Async.cs Pass reader options through async tar entry enumeration.
src/SharpCompress/Readers/ReaderOptions.cs Convert ReaderOptions to record implementing IReaderOptions and include extraction option properties.
src/SharpCompress/Readers/Rar/RarReaderEntry.cs Ensure RAR reader entries carry IReaderOptions via base Entry.
src/SharpCompress/Readers/Rar/RarReader.cs Propagate ReaderOptions into RAR reader entry construction.
src/SharpCompress/Readers/IReaderExtensions.cs Remove ExtractionOptions parameters and route extraction via entry.Options.
src/SharpCompress/Readers/IAsyncReaderExtensions.cs Remove ExtractionOptions parameters for async extraction helpers.
src/SharpCompress/Readers/Arj/ArjReader.cs Propagate ReaderOptions into ARJ entries.
src/SharpCompress/Readers/Arc/ArcReader.cs Propagate ReaderOptions into ARC entries.
src/SharpCompress/Readers/Arc/ArcReader.Async.cs Propagate ReaderOptions into async ARC entries.
src/SharpCompress/Readers/Ace/AceReader.cs Propagate ReaderOptions into ACE entries.
src/SharpCompress/Factories/ZipFactory.cs Accept IWriterOptions for zip writing (conversion logic introduced).
src/SharpCompress/Factories/TarFactory.cs Accept IWriterOptions for tar writing (conversion logic introduced).
src/SharpCompress/Factories/GZipFactory.cs Accept IWriterOptions for gzip writing (conversion logic introduced + compression-type check).
src/SharpCompress/Common/Zip/ZipEntry.cs Require IReaderOptions for entries and store it via base Entry.
src/SharpCompress/Common/Tar/TarEntry.cs Require IReaderOptions for entries and pass through enumerators.
src/SharpCompress/Common/Tar/TarEntry.Async.cs Require IReaderOptions for async entry enumeration.
src/SharpCompress/Common/SevenZip/SevenZipEntry.cs Require IReaderOptions for entries and store it via base Entry.
src/SharpCompress/Common/Rar/RarEntry.cs Ensure RAR entries require IReaderOptions (base constructor).
src/SharpCompress/Common/OptionsBase.cs Remove legacy OptionsBase.
src/SharpCompress/Common/Options/IWriterOptions.cs Add writer options interface.
src/SharpCompress/Common/Options/IStreamOptions.cs Add stream options interface (LeaveStreamOpen).
src/SharpCompress/Common/Options/IReaderOptions.cs Add reader options interface including extraction options.
src/SharpCompress/Common/Options/IProgressOptions.cs Add progress options interface.
src/SharpCompress/Common/Options/IExtractionOptions.cs Add extraction options interface (overwrite/fullpath/etc).
src/SharpCompress/Common/Options/IEncodingOptions.cs Add encoding options interface.
src/SharpCompress/Common/IsExternalInit.cs Add polyfill for init-only properties/records on legacy TFMs.
src/SharpCompress/Common/IEntry.cs Add Options property to entries to carry IReaderOptions.
src/SharpCompress/Common/IEntry.Extensions.cs Preserve times/attributes based on entry.Options (no per-call ExtractionOptions).
src/SharpCompress/Common/GZip/GZipVolume.cs Update to avoid mutating ReaderOptions (use with).
src/SharpCompress/Common/GZip/GZipEntry.cs Ensure gzip entries carry ReaderOptions and use new base constructor.
src/SharpCompress/Common/GZip/GZipEntry.Async.cs Ensure async gzip entries carry ReaderOptions.
src/SharpCompress/Common/ExtractionOptions.cs Remove legacy ExtractionOptions type.
src/SharpCompress/Common/ExtractionMethods.cs Use entry.Options instead of ExtractionOptions parameters; simplify delegates.
src/SharpCompress/Common/ExtractionMethods.Async.cs Async equivalent: use entry.Options and simplify delegates.
src/SharpCompress/Common/Entry.cs Add IReaderOptions Options storage on base entry and require it in constructor.
src/SharpCompress/Common/Arj/ArjEntry.cs Require IReaderOptions in constructor.
src/SharpCompress/Common/Arc/ArcEntry.cs Require IReaderOptions in constructor.
src/SharpCompress/Common/Ace/AceEntry.cs Require IReaderOptions in constructor.
src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs Pass archive ReaderOptions into writable zip entries.
src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs Require IReaderOptions when constructing archive entries.
src/SharpCompress/Archives/Zip/ZipArchive.cs Pass ReaderOptions into entries and accept IWriterOptions on save.
src/SharpCompress/Archives/Zip/ZipArchive.Async.cs Async equivalents for entry construction and save using IWriterOptions.
src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs Pass archive ReaderOptions into writable tar entries.
src/SharpCompress/Archives/Tar/TarArchiveEntry.cs Require IReaderOptions when constructing tar archive entries.
src/SharpCompress/Archives/Tar/TarArchive.cs Pass ReaderOptions into entries and accept IWriterOptions on save.
src/SharpCompress/Archives/Tar/TarArchive.Async.cs Async equivalents for tar entry construction and save using IWriterOptions.
src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs Pass ReaderOptions into sevenzip archive entries.
src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs Propagate ReaderOptions into created entry instances.
src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs Async propagation of ReaderOptions into entries.
src/SharpCompress/Archives/Rar/RarArchiveEntry.cs Ensure rar archive entries call base Entry(IReaderOptions).
src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs Avoid mutating ReaderOptions (use with).
src/SharpCompress/Archives/IWritableAsyncArchiveExtensions.cs Update save APIs to accept IWriterOptions.
src/SharpCompress/Archives/IWritableArchiveExtensions.cs Update save APIs to accept IWriterOptions.
src/SharpCompress/Archives/IWritableArchive.cs Update save APIs to accept IWriterOptions.
src/SharpCompress/Archives/IAsyncArchiveExtensions.cs Remove ExtractionOptions parameters from async archive extraction APIs.
src/SharpCompress/Archives/IArchiveExtensions.cs Remove ExtractionOptions parameters from sync archive extraction APIs.
src/SharpCompress/Archives/IArchiveEntryExtensions.cs Remove ExtractionOptions parameters from entry extraction APIs.
src/SharpCompress/Archives/IArchive.cs Add ReaderOptions to archive interface.
src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs Pass archive ReaderOptions into writable gzip entries.
src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs Require IReaderOptions for gzip archive entries.
src/SharpCompress/Archives/GZip/GZipArchive.cs Accept IWriterOptions on save and pass ReaderOptions into entries.
src/SharpCompress/Archives/GZip/GZipArchive.Async.cs Async equivalents for save/entry creation using IWriterOptions/ReaderOptions.
src/SharpCompress/Archives/ArchiveFactory.cs Change WriteToDirectory to accept ReaderOptions and use archive-level options.
src/SharpCompress/Archives/AbstractWritableArchive.cs Update save APIs to accept IWriterOptions.
src/SharpCompress/Archives/AbstractWritableArchive.Async.cs Update async save APIs to accept IWriterOptions.
src/SharpCompress/Archives/AbstractArchive.cs Expose ReaderOptions publicly (with protected setter) for propagation.
Comments suppressed due to low confidence (1)

src/SharpCompress/Common/IEntry.Extensions.cs:43

  • These 'if' statements can be combined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 47
@@ -40,7 +41,10 @@ protected override async ValueTask SaveToAsync(
{
throw new InvalidFormatException("Only one entry is allowed in a GZip Archive");
}
using var writer = new GZipWriter(stream, new GZipWriterOptions(options));
using var writer = new GZipWriter(
stream,
options as GZipWriterOptions ?? new GZipWriterOptions(options)
);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

SaveToAsync accepts IWriterOptions but does not validate options.CompressionType. For consistency with the sync path and GZipFactory.OpenWriter, consider throwing if options.CompressionType is not CompressionType.GZip to prevent silently ignoring a caller-provided compression type.

Copilot uses AI. Check for mistakes.
Comment on lines 12 to 16
/// This class is immutable. Use the <c>with</c> expression to create modified copies:
/// <code>
/// var options = new WriterOptions(CompressionType.Zip);
/// options = options with { LeaveStreamOpen = false };
/// </code>
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The XML doc example uses CompressionType.Zip, but SharpCompress.Common.CompressionType does not define a Zip member. This example won’t compile for consumers and is misleading; use a valid compression type (e.g., Deflate) or adjust the example to match supported values.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +17
/// This class is immutable. Use the <c>with</c> expression to create modified copies:
/// <code>
/// var options = new ZipWriterOptions(CompressionType.Zip);
/// options = options with { UseZip64 = true };
/// </code>
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The doc example references CompressionType.Zip, but the CompressionType enum has no Zip value. This will not compile for consumers; update the example to a supported compression type for ZIP archives (e.g., Deflate/LZMA/etc.).

Copilot uses AI. Check for mistakes.
Comment on lines +190 to +200
public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions)
{
ZipWriterOptions zipOptions = writerOptions switch
{
ZipWriterOptions zwo => zwo,
WriterOptions wo => new ZipWriterOptions(wo),
_ => throw new ArgumentException(
$"Expected WriterOptions or ZipWriterOptions, got {writerOptions.GetType().Name}",
nameof(writerOptions)
),
};
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

OpenWriter now accepts IWriterOptions, but the implementation throws for any implementation other than WriterOptions/ZipWriterOptions. This defeats the purpose of introducing IWriterOptions (custom implementations will fail). Consider accepting any IWriterOptions by defaulting to new ZipWriterOptions(writerOptions) (while still preserving the concrete ZipWriterOptions instance when provided).

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +230
public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions)
{
TarWriterOptions tarOptions = writerOptions switch
{
TarWriterOptions two => two,
WriterOptions wo => new TarWriterOptions(wo),
_ => throw new ArgumentException(
$"Expected WriterOptions or TarWriterOptions, got {writerOptions.GetType().Name}",
nameof(writerOptions)
),
};
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

OpenWriter accepts IWriterOptions, but currently throws unless the options are exactly WriterOptions/TarWriterOptions. This undermines the new interface-based API and prevents custom IWriterOptions implementations. Prefer converting from any IWriterOptions (e.g., writerOptions is TarWriterOptions two ? two : new TarWriterOptions(writerOptions)) instead of throwing.

Copilot uses AI. Check for mistakes.
Comment on lines +161 to +176
public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions)
{
if (writerOptions.CompressionType != CompressionType.GZip)
{
throw new InvalidFormatException("GZip archives only support GZip compression type.");
}
return new GZipWriter(stream, new GZipWriterOptions(writerOptions));

GZipWriterOptions gzipOptions = writerOptions switch
{
GZipWriterOptions gwo => gwo,
WriterOptions wo => new GZipWriterOptions(wo),
_ => throw new ArgumentException(
$"Expected WriterOptions or GZipWriterOptions, got {writerOptions.GetType().Name}",
nameof(writerOptions)
),
};
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

OpenWriter accepts IWriterOptions but throws for any implementation other than WriterOptions/GZipWriterOptions. With the new IWriterOptions API, custom implementations should be accepted as long as CompressionType == GZip; you can fall back to new GZipWriterOptions(writerOptions) for unknown implementations instead of throwing.

Copilot uses AI. Check for mistakes.
/// <summary>
/// The options used when opening this archive, including extraction behavior settings.
/// </summary>
ReaderOptions ReaderOptions { get; }
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

IArchive exposes ReaderOptions (concrete type) even though an IReaderOptions interface now exists and is used on entries. Exposing the concrete ReaderOptions type in the public interface reduces extensibility (custom IReaderOptions implementations can’t be surfaced). Consider changing this property to IReaderOptions (e.g., from SharpCompress.Common.Options) for consistency with the new options model.

Suggested change
ReaderOptions ReaderOptions { get; }
IReaderOptions ReaderOptions { get; }

Copilot uses AI. Check for mistakes.
Comment on lines 60 to 74
@@ -67,7 +68,10 @@ IEnumerable<GZipArchiveEntry> newEntries
{
throw new InvalidFormatException("Only one entry is allowed in a GZip Archive");
}
using var writer = new GZipWriter(stream, new GZipWriterOptions(options));
using var writer = new GZipWriter(
stream,
options as GZipWriterOptions ?? new GZipWriterOptions(options)
);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

GZipArchive.SaveTo accepts IWriterOptions, but it does not validate options.CompressionType. Passing new WriterOptions(CompressionType.BZip2) will silently produce a GZip archive anyway, which is inconsistent with GZipFactory.OpenWriter (which throws). Consider validating options.CompressionType == CompressionType.GZip here (and in the async variant) to avoid surprising behavior.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 10, 2026 11:10
@adamhathcock adamhathcock merged commit e1df655 into master Feb 10, 2026
6 checks passed
@adamhathcock adamhathcock deleted the adam/cleanup-options branch February 10, 2026 11:21
Copy link
Contributor

Copilot AI left a comment

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 127 out of 128 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (1)

src/SharpCompress/Common/IEntry.Extensions.cs:43

  • These 'if' statements can be combined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
using var stream = fileInfo.Open(FileMode.Create, FileAccess.Write);
await SaveToAsync(stream, new WriterOptions(CompressionType.GZip), cancellationToken)
await SaveToAsync(stream, new GZipWriterOptions(CompressionType.GZip), cancellationToken)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

GZipWriterOptions has no (CompressionType) constructor, so new GZipWriterOptions(CompressionType.GZip) will not compile here either. Use the parameterless constructor, or construct from WriterOptions/IWriterOptions.

Suggested change
await SaveToAsync(stream, new GZipWriterOptions(CompressionType.GZip), cancellationToken)
await SaveToAsync(stream, new GZipWriterOptions(), cancellationToken)

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +18
/// This class is immutable. Use the <c>with</c> expression to create modified copies:
/// <code>
/// var options = new ZipWriterOptions(CompressionType.Zip);
/// options = options with { UseZip64 = true };
/// </code>
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The XML doc example uses CompressionType.Zip, but SharpCompress.Common.CompressionType has no Zip member. Update the example to a valid compression type (e.g., CompressionType.Deflate).

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +16
/// This class is immutable. Use factory presets and fluent helpers for common configurations:
/// <code>
/// var options = ReaderOptions.ForExternalStream()
/// .WithPassword("secret")
/// .WithLookForHeader(true);
/// </code>
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

ReaderOptions.ForExternalStream is a property, not a method, so the example ReaderOptions.ForExternalStream() is incorrect and won’t compile. Update the docs snippet to use ReaderOptions.ForExternalStream (no parentheses).

Copilot uses AI. Check for mistakes.
Comment on lines 107 to +112
/// <summary>
/// An optional progress reporter for tracking compression operations.
/// When set, progress updates will be reported as entries are written.
/// Creates a new ZipWriterOptions for writing ZIP archives.
/// </summary>
public IProgress<ProgressReport>? Progress { get; set; }
/// <param name="compressionType">The compression type for the archive. Defaults to Deflate.</param>
public static WriterOptions ForZip(CompressionType compressionType = CompressionType.Deflate) =>
new(compressionType);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The summary for ForZip says it creates a ZipWriterOptions, but the method returns WriterOptions. This is misleading for API consumers; adjust the XML doc text to match the actual return type.

Copilot uses AI. Check for mistakes.
using (var archive = RarArchive.OpenArchive("Test.rar"))
// Using fluent factory method for extraction options
using (var archive = RarArchive.OpenArchive("Test.rar",
ReaderOptions.ForOwnedFile()
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The docs call ReaderOptions.ForOwnedFile() as if it were a method, but it’s a property (ReaderOptions.ForOwnedFile). As written, this sample won’t compile.

Suggested change
ReaderOptions.ForOwnedFile()
ReaderOptions.ForOwnedFile

Copilot uses AI. Check for mistakes.
}
};
// External stream with password and custom encoding
var options = ReaderOptions.ForExternalStream()
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The docs use ReaderOptions.ForExternalStream() here, but ForExternalStream is a property, not a method. Update the sample to ReaderOptions.ForExternalStream (no parentheses) so it compiles.

Suggested change
var options = ReaderOptions.ForExternalStream()
var options = ReaderOptions.ForExternalStream

Copilot uses AI. Check for mistakes.
});

var options = new ReaderOptions { Progress = progress };
var options = ReaderOptions.ForOwnedFile().WithProgress(progress);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This sample uses ReaderOptions.ForOwnedFile() but ForOwnedFile is a property. As written, the snippet won’t compile; use ReaderOptions.ForOwnedFile before chaining fluent helpers.

Suggested change
var options = ReaderOptions.ForOwnedFile().WithProgress(progress);
var options = ReaderOptions.ForOwnedFile.WithProgress(progress);

Copilot uses AI. Check for mistakes.
{
using var stream = fileInfo.Open(FileMode.Create, FileAccess.Write);
SaveTo(stream, new WriterOptions(CompressionType.GZip));
SaveTo(stream, new GZipWriterOptions(CompressionType.GZip));
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

GZipWriterOptions does not have a constructor that accepts CompressionType. This call will not compile; use new GZipWriterOptions() (or new GZipWriterOptions(new WriterOptions(CompressionType.GZip)) if you want to adapt from generic options).

Suggested change
SaveTo(stream, new GZipWriterOptions(CompressionType.GZip));
SaveTo(stream, new GZipWriterOptions());

Copilot uses AI. Check for mistakes.
Stream stream,
TOptions options,
IAsyncEnumerable<TEntry> oldEntries,
IEnumerable<TEntry> newEntries,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Local scope variable 'newEntries' shadows AbstractWritableArchive`3.newEntries.

Suggested change
IEnumerable<TEntry> newEntries,
IEnumerable<TEntry> newEntriesToSave,

Copilot uses AI. Check for mistakes.
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

Comments