renamed to ReaderOptions.ForFilePath

This commit is contained in:
Adam Hathcock
2026-03-03 12:40:58 +00:00
parent ba1cd66336
commit 0910f20c90
9 changed files with 25 additions and 14 deletions

View File

@@ -246,11 +246,12 @@ using (var archive = ZipArchive.OpenArchive("file.zip", options))
// Open-time presets
var external = ReaderOptions.ForExternalStream;
var owned = ReaderOptions.ForOwnedFile;
var owned = ReaderOptions.ForFilePath;
// Extraction presets
var safeOptions = ExtractionOptions.SafeExtract; // No overwrite
var flatOptions = ExtractionOptions.FlatExtract; // No directory structure
var metadataOptions = ExtractionOptions.PreserveMetadata; // Keep timestamps and attributes
// Factory defaults:
// - file path / FileInfo overloads use LeaveStreamOpen = false
@@ -329,7 +330,7 @@ ZipWriterEntryOptions: per-entry ZIP overrides (compression, level, timestamps,
```csharp
var registry = CompressionProviderRegistry.Default.With(new SystemGZipCompressionProvider());
var readerOptions = ReaderOptions.ForOwnedFile().WithProviders(registry);
var readerOptions = ReaderOptions.ForFilePath.WithProviders(registry);
var writerOptions = new WriterOptions(CompressionType.GZip)
{
CompressionLevel = 6,
@@ -417,7 +418,7 @@ var progress = new Progress<ProgressReport>(report =>
Console.WriteLine($"Extracting {report.EntryPath}: {report.PercentComplete}%");
});
var options = ReaderOptions.ForOwnedFile().WithProgress(progress);
var options = ReaderOptions.ForFilePath.WithProgress(progress);
using (var archive = ZipArchive.OpenArchive("archive.zip", options))
{
archive.WriteToDirectory(@"C:\output");

View File

@@ -95,7 +95,7 @@ Note: Extracting a solid rar or 7z file needs to be done in sequential order to
```C#
// Use ReaderOptions for open-time behavior and ExtractionOptions for extract-time behavior
using (var archive = RarArchive.OpenArchive("Test.rar", ReaderOptions.ForOwnedFile()))
using (var archive = RarArchive.OpenArchive("Test.rar", ReaderOptions.ForFilePath))
{
// Simple extraction with RarArchive; this WriteToDirectory pattern works for all archive types
archive.WriteToDirectory(
@@ -131,7 +131,7 @@ var progress = new Progress<ProgressReport>(report =>
});
using (var archive = RarArchive.OpenArchive("archive.rar",
ReaderOptions.ForOwnedFile()
ReaderOptions.ForFilePath
.WithProgress(progress))) // Must be solid Rar or 7Zip
{
archive.WriteToDirectory(
@@ -219,7 +219,7 @@ To replace a specific algorithm (for example to use `System.IO.Compression` for
var systemGZip = new SystemGZipCompressionProvider();
var customRegistry = CompressionProviderRegistry.Default.With(systemGZip);
var readerOptions = ReaderOptions.ForOwnedFile()
var readerOptions = ReaderOptions.ForFilePath
.WithProviders(customRegistry);
using var reader = ReaderFactory.OpenReader(stream, readerOptions);

View File

@@ -43,7 +43,7 @@ public static partial class ArchiveFactory
CancellationToken cancellationToken = default
)
{
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
var factory = await FindFactoryAsync<IArchiveFactory>(fileInfo, cancellationToken)
.ConfigureAwait(false);
@@ -73,7 +73,7 @@ public static partial class ArchiveFactory
}
fileInfo.NotNull(nameof(fileInfo));
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
var factory = await FindFactoryAsync<IMultiArchiveFactory>(fileInfo, cancellationToken)
.ConfigureAwait(false);

View File

@@ -40,7 +40,7 @@ public static partial class ArchiveFactory
public static IArchive OpenArchive(FileInfo fileInfo, ReaderOptions? options = null)
{
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
return FindFactory<IArchiveFactory>(fileInfo).OpenArchive(fileInfo, options);
}
@@ -64,7 +64,7 @@ public static partial class ArchiveFactory
}
fileInfo.NotNull(nameof(fileInfo));
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
return FindFactory<IMultiArchiveFactory>(fileInfo).OpenArchive(filesArray, options);
}

View File

@@ -97,6 +97,12 @@ public sealed record ExtractionOptions : IExtractionOptions
/// </summary>
public static ExtractionOptions FlatExtract => new(extractFullPath: false, overwrite: true);
/// <summary>
/// Gets an ExtractionOptions instance configured to preserve timestamps and attributes.
/// </summary>
public static ExtractionOptions PreserveMetadata =>
new() { PreserveFileTime = true, PreserveAttributes = true };
/// <summary>
/// Default symbolic link handler that logs a warning message.
/// </summary>

View File

@@ -41,7 +41,7 @@ public static partial class ReaderFactory
CancellationToken cancellationToken = default
)
{
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
var stream = fileInfo.OpenAsyncReadStream(cancellationToken);
return await OpenAsyncReader(stream, options, cancellationToken).ConfigureAwait(false);
}

View File

@@ -17,7 +17,7 @@ public static partial class ReaderFactory
public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? options = null)
{
options ??= ReaderOptions.ForOwnedFile;
options ??= ReaderOptions.ForFilePath;
return OpenReader(fileInfo.OpenRead(), options);
}

View File

@@ -128,7 +128,7 @@ public sealed record ReaderOptions : IReaderOptions
/// <summary>
/// Gets ReaderOptions configured for file-based overloads that open their own stream.
/// </summary>
public static ReaderOptions ForOwnedFile => new() { LeaveStreamOpen = false };
public static ReaderOptions ForFilePath => new() { LeaveStreamOpen = false };
/// <summary>
/// Creates ReaderOptions for reading encrypted archives.

View File

@@ -209,7 +209,7 @@ public class OptionsUsabilityTests : TestBase
var external = ReaderOptions.ForExternalStream;
Assert.True(external.LeaveStreamOpen);
var owned = ReaderOptions.ForOwnedFile;
var owned = ReaderOptions.ForFilePath;
Assert.False(owned.LeaveStreamOpen);
}
@@ -222,6 +222,10 @@ public class OptionsUsabilityTests : TestBase
var flat = ExtractionOptions.FlatExtract;
Assert.False(flat.ExtractFullPath);
Assert.True(flat.Overwrite);
var preserveMetadata = ExtractionOptions.PreserveMetadata;
Assert.True(preserveMetadata.PreserveFileTime);
Assert.True(preserveMetadata.PreserveAttributes);
}
[Fact]