From 0910f20c90e4cfdae663f2f640649ce38e6e5541 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 3 Mar 2026 12:40:58 +0000 Subject: [PATCH] renamed to ReaderOptions.ForFilePath --- docs/API.md | 7 ++++--- docs/USAGE.md | 6 +++--- src/SharpCompress/Archives/ArchiveFactory.Async.cs | 4 ++-- src/SharpCompress/Archives/ArchiveFactory.cs | 4 ++-- src/SharpCompress/Common/ExtractionOptions.cs | 6 ++++++ src/SharpCompress/Readers/ReaderFactory.Async.cs | 2 +- src/SharpCompress/Readers/ReaderFactory.cs | 2 +- src/SharpCompress/Readers/ReaderOptions.cs | 2 +- tests/SharpCompress.Test/OptionsUsabilityTests.cs | 6 +++++- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/docs/API.md b/docs/API.md index 9a6657a6..688c4119 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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(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"); diff --git a/docs/USAGE.md b/docs/USAGE.md index a8d44ffe..e28e50e4 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -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(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); diff --git a/src/SharpCompress/Archives/ArchiveFactory.Async.cs b/src/SharpCompress/Archives/ArchiveFactory.Async.cs index 8e5f7d90..82a40a16 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.Async.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.Async.cs @@ -43,7 +43,7 @@ public static partial class ArchiveFactory CancellationToken cancellationToken = default ) { - options ??= ReaderOptions.ForOwnedFile; + options ??= ReaderOptions.ForFilePath; var factory = await FindFactoryAsync(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(fileInfo, cancellationToken) .ConfigureAwait(false); diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index d3fbde42..85cf0058 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -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(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(fileInfo).OpenArchive(filesArray, options); } diff --git a/src/SharpCompress/Common/ExtractionOptions.cs b/src/SharpCompress/Common/ExtractionOptions.cs index 4f6a3e9b..84a6bffe 100644 --- a/src/SharpCompress/Common/ExtractionOptions.cs +++ b/src/SharpCompress/Common/ExtractionOptions.cs @@ -97,6 +97,12 @@ public sealed record ExtractionOptions : IExtractionOptions /// public static ExtractionOptions FlatExtract => new(extractFullPath: false, overwrite: true); + /// + /// Gets an ExtractionOptions instance configured to preserve timestamps and attributes. + /// + public static ExtractionOptions PreserveMetadata => + new() { PreserveFileTime = true, PreserveAttributes = true }; + /// /// Default symbolic link handler that logs a warning message. /// diff --git a/src/SharpCompress/Readers/ReaderFactory.Async.cs b/src/SharpCompress/Readers/ReaderFactory.Async.cs index e3f3a4be..0119bd52 100644 --- a/src/SharpCompress/Readers/ReaderFactory.Async.cs +++ b/src/SharpCompress/Readers/ReaderFactory.Async.cs @@ -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); } diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index 6a729b55..a1ff1775 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -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); } diff --git a/src/SharpCompress/Readers/ReaderOptions.cs b/src/SharpCompress/Readers/ReaderOptions.cs index 51e0254d..d2fa3f97 100644 --- a/src/SharpCompress/Readers/ReaderOptions.cs +++ b/src/SharpCompress/Readers/ReaderOptions.cs @@ -128,7 +128,7 @@ public sealed record ReaderOptions : IReaderOptions /// /// Gets ReaderOptions configured for file-based overloads that open their own stream. /// - public static ReaderOptions ForOwnedFile => new() { LeaveStreamOpen = false }; + public static ReaderOptions ForFilePath => new() { LeaveStreamOpen = false }; /// /// Creates ReaderOptions for reading encrypted archives. diff --git a/tests/SharpCompress.Test/OptionsUsabilityTests.cs b/tests/SharpCompress.Test/OptionsUsabilityTests.cs index 58314b12..70b73cb7 100644 --- a/tests/SharpCompress.Test/OptionsUsabilityTests.cs +++ b/tests/SharpCompress.Test/OptionsUsabilityTests.cs @@ -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]