diff --git a/src/SharpCompress/Archives/AbstractArchive.cs b/src/SharpCompress/Archives/AbstractArchive.cs index 7d89067fa..1e4b353b9 100644 --- a/src/SharpCompress/Archives/AbstractArchive.cs +++ b/src/SharpCompress/Archives/AbstractArchive.cs @@ -40,7 +40,7 @@ internal AbstractArchive(ArchiveType type, SourceStream sourceStream) internal AbstractArchive(ArchiveType type) { Type = type; - ReaderOptions = new(); + ReaderOptions = ReaderOptions.Default; _lazyVolumes = new LazyReadOnlyCollection(Enumerable.Empty()); _lazyEntries = new LazyReadOnlyCollection(Enumerable.Empty()); _lazyVolumesAsync = new LazyAsyncReadOnlyCollection( diff --git a/src/SharpCompress/Archives/ArchiveFactory.Async.cs b/src/SharpCompress/Archives/ArchiveFactory.Async.cs index 035955541..fde9a93db 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.Async.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.Async.cs @@ -33,7 +33,11 @@ public static ValueTask OpenAsyncArchive( ) { filePath.NotNullOrEmpty(nameof(filePath)); - return OpenAsyncArchive(new FileInfo(filePath), options, cancellationToken); + return OpenAsyncArchive( + new FileInfo(filePath), + options ?? ReaderOptions.ForFilePath, + cancellationToken + ); } public static async ValueTask OpenAsyncArchive( diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index e4973f0fe..ec044e0e8 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -37,7 +37,7 @@ public static IWritableArchive CreateArchive() public static IArchive OpenArchive(string filePath, ReaderOptions? options = null) { filePath.NotNullOrEmpty(nameof(filePath)); - return OpenArchive(new FileInfo(filePath), options); + return OpenArchive(new FileInfo(filePath), options ?? ReaderOptions.ForFilePath); } public static IArchive OpenArchive(FileInfo fileInfo, ReaderOptions? options = null) diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs index 788d1f393..54c99a938 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs @@ -15,18 +15,17 @@ namespace SharpCompress.Archives.Rar; internal class FileInfoRarArchiveVolume : RarVolume { internal FileInfoRarArchiveVolume(FileInfo fileInfo, ReaderOptions options, int index) - : base(StreamingMode.Seekable, fileInfo.OpenRead(), FixOptions(options), index) + : base( + StreamingMode.Seekable, + fileInfo.OpenRead(), + options.WithLeaveStreamOpen(false), + index + ) { FileInfo = fileInfo; FileParts = GetVolumeFileParts().ToArray().ToReadOnly(); } - private static ReaderOptions FixOptions(ReaderOptions options) - { - //make sure we're closing streams with fileinfo - return options with { LeaveStreamOpen = false }; - } - internal ReadOnlyCollection FileParts { get; } internal FileInfo FileInfo { get; } diff --git a/src/SharpCompress/Archives/Rar/RarArchive.Factory.cs b/src/SharpCompress/Archives/Rar/RarArchive.Factory.cs index 432bf54f6..df820e2fc 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.Factory.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.Factory.cs @@ -51,7 +51,7 @@ public static IRarArchive OpenArchive(FileInfo fileInfo, ReaderOptions? readerOp new SourceStream( fileInfo, i => RarArchiveVolumeFactory.GetFilePart(i, fileInfo), - readerOptions ?? new ReaderOptions() + readerOptions ?? ReaderOptions.ForFilePath ) ); } @@ -66,7 +66,7 @@ public static IRarArchive OpenArchive(Stream stream, ReaderOptions? readerOption } return new RarArchive( - new SourceStream(stream, _ => null, readerOptions ?? new ReaderOptions()) + new SourceStream(stream, _ => null, readerOptions ?? ReaderOptions.ForExternalStream) ); } diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs index 75255b25d..97c412e6f 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs @@ -45,7 +45,7 @@ var h in headerFactory.NotNull().ReadSeekableHeaderAsync(volsArray.Last().Stream s = new SourceStream( v[0].Stream, i => i < v.Length ? v[i].Stream : null, - new ReaderOptions() { LeaveStreamOpen = true } + ReaderOptions.ForExternalStream ); } else diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 206048142..3b5fd5b28 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -86,7 +86,7 @@ protected override IEnumerable LoadEntries(IEnumerable i < v.Length ? v[i].Stream : null, - new ReaderOptions() { LeaveStreamOpen = true } + ReaderOptions.ForExternalStream ); } else diff --git a/src/SharpCompress/Common/ExtractionMethods.Async.cs b/src/SharpCompress/Common/ExtractionMethods.Async.cs index 8792e06bb..053e62f74 100644 --- a/src/SharpCompress/Common/ExtractionMethods.Async.cs +++ b/src/SharpCompress/Common/ExtractionMethods.Async.cs @@ -90,15 +90,7 @@ public static async ValueTask WriteEntryToFileAsync( options ??= new ExtractionOptions(); if (entry.LinkTarget != null) { - if (options.SymbolicLinkHandler is not null) - { - options.SymbolicLinkHandler(destinationFileName, entry.LinkTarget); - } - else - { - ExtractionOptions.DefaultSymbolicLinkHandler(destinationFileName, entry.LinkTarget); - } - return; + options.SymbolicLinkHandler?.Invoke(destinationFileName, entry.LinkTarget); } else { diff --git a/src/SharpCompress/Common/ExtractionMethods.cs b/src/SharpCompress/Common/ExtractionMethods.cs index 526c6e263..f7980fa80 100644 --- a/src/SharpCompress/Common/ExtractionMethods.cs +++ b/src/SharpCompress/Common/ExtractionMethods.cs @@ -99,15 +99,7 @@ Action openAndWrite options ??= new ExtractionOptions(); if (entry.LinkTarget != null) { - if (options.SymbolicLinkHandler is not null) - { - options.SymbolicLinkHandler(destinationFileName, entry.LinkTarget); - } - else - { - ExtractionOptions.DefaultSymbolicLinkHandler(destinationFileName, entry.LinkTarget); - } - return; + options.SymbolicLinkHandler?.Invoke(destinationFileName, entry.LinkTarget); } else { diff --git a/src/SharpCompress/Common/ExtractionOptions.cs b/src/SharpCompress/Common/ExtractionOptions.cs index 84a6bffec..ea84ed53e 100644 --- a/src/SharpCompress/Common/ExtractionOptions.cs +++ b/src/SharpCompress/Common/ExtractionOptions.cs @@ -45,7 +45,7 @@ public sealed record ExtractionOptions : IExtractionOptions /// /// /// Breaking change: Changed from field to init-only property in version 0.40.0. - /// The default handler logs a warning message. + /// If no handler is provided, symbolic links are silently skipped during extraction. /// public Action? SymbolicLinkHandler { get; init; } @@ -58,10 +58,7 @@ public ExtractionOptions() { } /// Creates a new ExtractionOptions instance with the specified overwrite behavior. /// /// Whether to overwrite existing files. - public ExtractionOptions(bool overwrite) - { - Overwrite = overwrite; - } + public ExtractionOptions(bool overwrite) => Overwrite = overwrite; /// /// Creates a new ExtractionOptions instance with the specified extraction path and overwrite behavior. @@ -102,14 +99,4 @@ public ExtractionOptions(bool extractFullPath, bool overwrite, bool preserveFile /// public static ExtractionOptions PreserveMetadata => new() { PreserveFileTime = true, PreserveAttributes = true }; - - /// - /// Default symbolic link handler that logs a warning message. - /// - public static void DefaultSymbolicLinkHandler(string sourcePath, string targetPath) - { - Console.WriteLine( - $"Could not write symlink {sourcePath} -> {targetPath}, for more information please see https://github.com/dotnet/runtime/issues/24271" - ); - } } diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index cb821acff..b753c3ad5 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -5,11 +5,11 @@ namespace SharpCompress.Common.GZip; public class GZipVolume : Volume { - public GZipVolume(Stream stream, ReaderOptions? options, int index) + public GZipVolume(Stream stream, ReaderOptions options, int index) : base(stream, options, index) { } public GZipVolume(FileInfo fileInfo, ReaderOptions options) - : base(fileInfo.OpenRead(), options with { LeaveStreamOpen = false }) { } + : base(fileInfo.OpenRead(), options.WithLeaveStreamOpen(false)) { } public override bool IsFirstVolume => true; diff --git a/src/SharpCompress/Common/Lzw/LzwVolume.cs b/src/SharpCompress/Common/Lzw/LzwVolume.cs index 7ded1d267..be50f1061 100644 --- a/src/SharpCompress/Common/Lzw/LzwVolume.cs +++ b/src/SharpCompress/Common/Lzw/LzwVolume.cs @@ -5,11 +5,11 @@ namespace SharpCompress.Common.Lzw; public class LzwVolume : Volume { - public LzwVolume(Stream stream, ReaderOptions? options, int index) + public LzwVolume(Stream stream, ReaderOptions options, int index) : base(stream, options, index) { } public LzwVolume(FileInfo fileInfo, ReaderOptions options) - : base(fileInfo.OpenRead(), options with { LeaveStreamOpen = false }) { } + : base(fileInfo.OpenRead(), options.WithLeaveStreamOpen(false)) { } public override bool IsFirstVolume => true; diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index d00ed4f0b..ffca18c32 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -11,10 +11,10 @@ public abstract partial class Volume : IVolume, IAsyncDisposable private readonly Stream _baseStream; private readonly Stream _actualStream; - internal Volume(Stream stream, ReaderOptions? readerOptions, int index = 0) + internal Volume(Stream stream, ReaderOptions readerOptions, int index = 0) { Index = index; - ReaderOptions = readerOptions ?? new ReaderOptions(); + ReaderOptions = readerOptions; _baseStream = stream; // Only rewind if it's a buffered SharpCompressStream (not passthrough) diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index 0a47d3b75..56d0a73b9 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -317,7 +317,7 @@ public async ValueTask OpenAsyncArchive( /// public IReader OpenReader(Stream stream, ReaderOptions? options) { - options ??= new ReaderOptions(); + options ??= ReaderOptions.ForExternalStream; var sharpCompressStream = new SharpCompressStream(stream); sharpCompressStream.StartRecording(TarWrapper.MaximumRewindBufferSize); foreach (var wrapper in TarWrapper.Wrappers) @@ -350,7 +350,7 @@ public async ValueTask OpenAsyncReader( ) { cancellationToken.ThrowIfCancellationRequested(); - options ??= new ReaderOptions(); + options ??= ReaderOptions.ForExternalStream; var sharpCompressStream = new SharpCompressStream(stream); sharpCompressStream.StartRecording(TarWrapper.MaximumRewindBufferSize); foreach (var wrapper in TarWrapper.Wrappers) diff --git a/src/SharpCompress/Readers/Ace/AceReader.Factory.cs b/src/SharpCompress/Readers/Ace/AceReader.Factory.cs index a4ae43bb7..5977e8ded 100644 --- a/src/SharpCompress/Readers/Ace/AceReader.Factory.cs +++ b/src/SharpCompress/Readers/Ace/AceReader.Factory.cs @@ -20,7 +20,7 @@ public partial class AceReader public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new SingleVolumeAceReader(stream, readerOptions ?? new ReaderOptions()); + return new SingleVolumeAceReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } /// @@ -32,7 +32,7 @@ public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = n public static IReader OpenReader(IEnumerable streams, ReaderOptions? options = null) { streams.NotNull(nameof(streams)); - return new MultiVolumeAceReader(streams, options ?? new ReaderOptions()); + return new MultiVolumeAceReader(streams, options ?? ReaderOptions.ForExternalStream); } public static ValueTask OpenAsyncReader( @@ -62,7 +62,7 @@ public static IAsyncReader OpenAsyncReader( ) { streams.NotNull(nameof(streams)); - return new MultiVolumeAceReader(streams, options ?? new ReaderOptions()); + return new MultiVolumeAceReader(streams, options ?? ReaderOptions.ForExternalStream); } public static ValueTask OpenAsyncReader( diff --git a/src/SharpCompress/Readers/Arc/ArcReader.cs b/src/SharpCompress/Readers/Arc/ArcReader.cs index 376d598e2..c1b533665 100644 --- a/src/SharpCompress/Readers/Arc/ArcReader.cs +++ b/src/SharpCompress/Readers/Arc/ArcReader.cs @@ -25,7 +25,7 @@ private ArcReader(Stream stream, ReaderOptions options) public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new ArcReader(stream, readerOptions ?? new ReaderOptions()); + return new ArcReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } protected override IEnumerable GetEntries(Stream stream) diff --git a/src/SharpCompress/Readers/Arj/ArjReader.cs b/src/SharpCompress/Readers/Arj/ArjReader.cs index d5a0ae741..a0c4899c4 100644 --- a/src/SharpCompress/Readers/Arj/ArjReader.cs +++ b/src/SharpCompress/Readers/Arj/ArjReader.cs @@ -32,7 +32,7 @@ internal ArjReader(ReaderOptions options) public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new SingleVolumeArjReader(stream, readerOptions ?? new ReaderOptions()); + return new SingleVolumeArjReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } /// @@ -44,7 +44,7 @@ public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = n public static IReader OpenReader(IEnumerable streams, ReaderOptions? options = null) { streams.NotNull(nameof(streams)); - return new MultiVolumeArjReader(streams, options ?? new ReaderOptions()); + return new MultiVolumeArjReader(streams, options ?? ReaderOptions.ForExternalStream); } protected abstract void ValidateArchive(ArjVolume archive); diff --git a/src/SharpCompress/Readers/GZip/GZipReader.Factory.cs b/src/SharpCompress/Readers/GZip/GZipReader.Factory.cs index 8baf715d0..bd593f209 100644 --- a/src/SharpCompress/Readers/GZip/GZipReader.Factory.cs +++ b/src/SharpCompress/Readers/GZip/GZipReader.Factory.cs @@ -56,6 +56,6 @@ public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? readerOptions public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new GZipReader(stream, readerOptions ?? new ReaderOptions()); + return new GZipReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } } diff --git a/src/SharpCompress/Readers/Lzw/LzwReader.Factory.cs b/src/SharpCompress/Readers/Lzw/LzwReader.Factory.cs index b62e7b5f9..e2166e37d 100644 --- a/src/SharpCompress/Readers/Lzw/LzwReader.Factory.cs +++ b/src/SharpCompress/Readers/Lzw/LzwReader.Factory.cs @@ -56,6 +56,6 @@ public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? readerOptions public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new LzwReader(stream, readerOptions ?? new ReaderOptions()); + return new LzwReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } } diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index a6a8ede78..81a5457c7 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -72,7 +72,7 @@ public static IReader OpenReader(IEnumerable fileInfos, ReaderOptions? public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new SingleVolumeRarReader(stream, readerOptions ?? new ReaderOptions()); + return new SingleVolumeRarReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } /// @@ -84,7 +84,7 @@ public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = n public static IReader OpenReader(IEnumerable streams, ReaderOptions? options = null) { streams.NotNull(nameof(streams)); - return new MultiVolumeRarReader(streams, options ?? new ReaderOptions()); + return new MultiVolumeRarReader(streams, options ?? ReaderOptions.ForExternalStream); } protected override IEnumerable GetEntries(Stream stream) diff --git a/src/SharpCompress/Readers/ReaderFactory.Async.cs b/src/SharpCompress/Readers/ReaderFactory.Async.cs index 0119bd52e..803885776 100644 --- a/src/SharpCompress/Readers/ReaderFactory.Async.cs +++ b/src/SharpCompress/Readers/ReaderFactory.Async.cs @@ -25,7 +25,11 @@ public static ValueTask OpenAsyncReader( ) { filePath.NotNullOrEmpty(nameof(filePath)); - return OpenAsyncReader(new FileInfo(filePath), options, cancellationToken); + return OpenAsyncReader( + new FileInfo(filePath), + options ?? ReaderOptions.ForFilePath, + cancellationToken + ); } /// diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index a1ff17752..2a84913cd 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -12,7 +12,7 @@ public static partial class ReaderFactory public static IReader OpenReader(string filePath, ReaderOptions? options = null) { filePath.NotNullOrEmpty(nameof(filePath)); - return OpenReader(new FileInfo(filePath), options); + return OpenReader(new FileInfo(filePath), options ?? ReaderOptions.ForFilePath); } public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? options = null) diff --git a/src/SharpCompress/Readers/ReaderOptions.cs b/src/SharpCompress/Readers/ReaderOptions.cs index cc90224af..109e3e932 100644 --- a/src/SharpCompress/Readers/ReaderOptions.cs +++ b/src/SharpCompress/Readers/ReaderOptions.cs @@ -151,35 +151,34 @@ public ReaderOptions() { } /// /// Gets ReaderOptions configured for caller-provided streams. /// - public static ReaderOptions ForExternalStream => new() { LeaveStreamOpen = true }; + internal static ReaderOptions Default => new(); + + public static ReaderOptions ForExternalStream => Default.WithLeaveStreamOpen(true); /// /// Gets ReaderOptions configured for file-based overloads that open their own stream. /// - public static ReaderOptions ForFilePath => new() { LeaveStreamOpen = false }; + public static ReaderOptions ForFilePath => Default; /// /// Creates ReaderOptions for reading encrypted archives. /// /// The password for encrypted archives. public static ReaderOptions ForEncryptedArchive(string? password = null) => - new ReaderOptions().WithPassword(password); + Default.WithPassword(password); /// /// Creates ReaderOptions for archives with custom character encoding. /// /// The encoding for archive entry names. public static ReaderOptions ForEncoding(IArchiveEncoding encoding) => - new ReaderOptions().WithArchiveEncoding(encoding); + Default.WithArchiveEncoding(encoding); /// /// Creates ReaderOptions for self-extracting archives that require header search. /// public static ReaderOptions ForSelfExtractingArchive(string? password = null) => - new ReaderOptions() - .WithLookForHeader(true) - .WithPassword(password) - .WithRewindableBufferSize(1_048_576); // 1MB for SFX archives + Default.WithLookForHeader(true).WithPassword(password).WithRewindableBufferSize(1_048_576); // 1MB for SFX archives // Note: Parameterized constructors have been removed. // Use fluent With*() helpers or object initializers instead: diff --git a/src/SharpCompress/Readers/Tar/TarReader.Factory.cs b/src/SharpCompress/Readers/Tar/TarReader.Factory.cs index e6e5a7032..aae20bb4c 100644 --- a/src/SharpCompress/Readers/Tar/TarReader.Factory.cs +++ b/src/SharpCompress/Readers/Tar/TarReader.Factory.cs @@ -89,7 +89,7 @@ public static async ValueTask OpenAsyncReader( { cancellationToken.ThrowIfCancellationRequested(); stream.NotNull(nameof(stream)); - readerOptions ??= new ReaderOptions(); + readerOptions ??= ReaderOptions.ForExternalStream; var sharpCompressStream = SharpCompressStream.Create( stream, bufferSize: Math.Max( @@ -171,7 +171,7 @@ public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? readerOptions public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - readerOptions ??= new ReaderOptions(); + readerOptions ??= ReaderOptions.ForExternalStream; var sharpCompressStream = SharpCompressStream.Create( stream, bufferSize: Math.Max( diff --git a/src/SharpCompress/Readers/Zip/ZipReader.cs b/src/SharpCompress/Readers/Zip/ZipReader.cs index 91dff5bfe..e2019de65 100644 --- a/src/SharpCompress/Readers/Zip/ZipReader.cs +++ b/src/SharpCompress/Readers/Zip/ZipReader.cs @@ -48,7 +48,7 @@ private ZipReader(Stream stream, ReaderOptions options, IEnumerable en public static IReader OpenReader(Stream stream, ReaderOptions? readerOptions = null) { stream.NotNull(nameof(stream)); - return new ZipReader(stream, readerOptions ?? new ReaderOptions()); + return new ZipReader(stream, readerOptions ?? ReaderOptions.ForExternalStream); } public static IReader OpenReader( @@ -58,7 +58,7 @@ IEnumerable entries ) { stream.NotNull(nameof(stream)); - return new ZipReader(stream, options ?? new ReaderOptions(), entries); + return new ZipReader(stream, options ?? ReaderOptions.ForExternalStream, entries); } #endregion Open diff --git a/src/SharpCompress/Writers/WriterOptions.cs b/src/SharpCompress/Writers/WriterOptions.cs index cc0e0370e..6415ca3e0 100644 --- a/src/SharpCompress/Writers/WriterOptions.cs +++ b/src/SharpCompress/Writers/WriterOptions.cs @@ -1,7 +1,6 @@ using System; using SharpCompress.Common; using SharpCompress.Common.Options; -using SharpCompress.Compressors; using SharpCompress.Providers; using D = SharpCompress.Compressors.Deflate; @@ -18,17 +17,10 @@ namespace SharpCompress.Writers; /// public sealed record WriterOptions : IWriterOptions { - private CompressionType _compressionType; - private int _compressionLevel; - /// /// The compression type to use for the archive. /// - public CompressionType CompressionType - { - get => _compressionType; - init => _compressionType = value; - } + public CompressionType CompressionType { get; init; } /// /// The compression level to be used when the compression type supports variable levels. @@ -40,11 +32,11 @@ public CompressionType CompressionType /// public int CompressionLevel { - get => _compressionLevel; + get; init { CompressionLevelValidation.Validate(CompressionType, value); - _compressionLevel = value; + field = value; } } diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json index 03c03a9a4..a401c7021 100644 --- a/src/SharpCompress/packages.lock.json +++ b/src/SharpCompress/packages.lock.json @@ -268,9 +268,9 @@ "net10.0": { "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[10.0.5, )", - "resolved": "10.0.5", - "contentHash": "A+5ZuQ0f449tM+MQrhf6R9ZX7lYpjk/ODEwLYKrnF6111rtARx8fVsm4YznUnQiKnnXfaXNBqgxmil6RW3L3SA==" + "requested": "[10.0.0, )", + "resolved": "10.0.0", + "contentHash": "kICGrGYEzCNI3wPzfEXcwNHgTvlvVn9yJDhSdRK+oZQy4jvYH529u7O0xf5ocQKzOMjfS07+3z9PKRIjrFMJDA==" }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", @@ -400,9 +400,9 @@ "net8.0": { "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[8.0.25, )", - "resolved": "8.0.25", - "contentHash": "sqX4nmBft05ivqKvUT4nxaN8rT3apCLt9SWFkfRrQPwra1zPwFknQAw1lleuMCKOCLvVmOWwrC2iPSm9RiXZUg==" + "requested": "[8.0.22, )", + "resolved": "8.0.22", + "contentHash": "MhcMithKEiyyNkD2ZfbDZPmcOdi0GheGfg8saEIIEfD/fol3iHmcV8TsZkD4ZYz5gdUuoX4YtlVySUU7Sxl9SQ==" }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", diff --git a/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs b/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs index 67abff6ab..634f39403 100644 --- a/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs +++ b/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs @@ -70,7 +70,7 @@ public void SystemTarExtractArchiveApi() using var stream = new MemoryStream(_tarBytes); using var archive = TarArchive.OpenArchive( stream, - new ReaderOptions().WithProviders( + ReaderOptions.ForExternalStream.WithProviders( CompressionProviderRegistry.Empty.With(new SystemGZipCompressionProvider()) ) ); @@ -87,7 +87,7 @@ public void SystemTarExtractReaderApi() using var stream = new MemoryStream(_tarBytes); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions().WithProviders( + ReaderOptions.ForExternalStream.WithProviders( CompressionProviderRegistry.Empty.With(new SystemGZipCompressionProvider()) ) ); diff --git a/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs b/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs index bd8188532..c5b3e090d 100644 --- a/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs +++ b/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs @@ -32,7 +32,7 @@ public void SystemZipExtractArchiveApi() using var stream = new MemoryStream(_archiveBytes); using var archive = ZipArchive.OpenArchive( stream, - new ReaderOptions().WithProviders( + ReaderOptions.ForExternalStream.WithProviders( CompressionProviderRegistry.Empty.With(new SystemDeflateCompressionProvider()) ) ); @@ -73,7 +73,7 @@ public void SystemZipExtractReaderApi() using var stream = new MemoryStream(_archiveBytes); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions().WithProviders( + ReaderOptions.ForExternalStream.WithProviders( CompressionProviderRegistry.Empty.With(new SystemDeflateCompressionProvider()) ) ); diff --git a/tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs b/tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs index 62d10265e..332ca6527 100644 --- a/tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs +++ b/tests/SharpCompress.Test/Ace/AceReaderAsyncTests.cs @@ -73,7 +73,7 @@ private async Task ReadAsync(string testArchive, CompressionType expectedCompres using Stream stream = File.OpenRead(testArchive); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions() + ReaderOptions.ForExternalStream ); while (await reader.MoveToNextEntryAsync()) { @@ -95,7 +95,10 @@ CompressionType expectedCompression using Stream stream = File.OpenRead(testArchive); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (await reader.MoveToNextEntryAsync()) { diff --git a/tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs b/tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs index 17dfa9cf2..c2418e4b0 100644 --- a/tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs +++ b/tests/SharpCompress.Test/Arj/ArjReaderAsyncTests.cs @@ -94,7 +94,7 @@ private async Task ReadAsync(string testArchive, CompressionType? expectedCompre using Stream stream = File.OpenRead(testArchive); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions() + ReaderOptions.ForExternalStream ); while (await reader.MoveToNextEntryAsync()) { @@ -119,7 +119,10 @@ CompressionType expectedCompression using Stream stream = File.OpenRead(testArchive); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions() { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (await reader.MoveToNextEntryAsync()) { diff --git a/tests/SharpCompress.Test/CompressionProviderTests.cs b/tests/SharpCompress.Test/CompressionProviderTests.cs index 8578de9df..1b043efd4 100644 --- a/tests/SharpCompress.Test/CompressionProviderTests.cs +++ b/tests/SharpCompress.Test/CompressionProviderTests.cs @@ -332,7 +332,10 @@ public void GZipProvider_Decompress_WithReaderOptionsContext_UsesArchiveEncoding ); compressedStream.Position = 0; - var readerOptions = new ReaderOptions { ArchiveEncoding = archiveEncoding }; + var readerOptions = ReaderOptions.ForExternalStream with + { + ArchiveEncoding = archiveEncoding, + }; var context = CompressionContext.FromStream(compressedStream) with { ReaderOptions = readerOptions, @@ -433,7 +436,7 @@ public void TarReader_WithCustomProvider_UsesProvider() archiveStream.Position = 0; var customProvider = new GZipCompressionProvider(); var registry = CompressionProviderRegistry.Default.With(customProvider); - var readOptions = new ReaderOptions { Providers = registry }; + var readOptions = ReaderOptions.ForExternalStream.WithProviders(registry); using var reader = TarReader.OpenReader(archiveStream, readOptions); reader.MoveToNextEntry().Should().BeTrue(); @@ -462,7 +465,7 @@ public void TarReader_OpenReader_WithContextRequiredGZipProvider_Succeeds() archiveStream.Position = 0; var registry = CompressionProviderRegistry.Default.With(new ContextRequiredGZipProvider()); - var readOptions = new ReaderOptions { Providers = registry }; + var readOptions = ReaderOptions.ForExternalStream.WithProviders(registry); using var reader = TarReader.OpenReader(archiveStream, readOptions); reader.MoveToNextEntry().Should().BeTrue(); @@ -504,7 +507,11 @@ public void ReaderOptions_WithProviders_CanBeCloned() var customProvider = new DeflateCompressionProvider(); var registry = CompressionProviderRegistry.Default.With(customProvider); - var original = new ReaderOptions { Providers = registry, LeaveStreamOpen = false }; + var original = ReaderOptions.ForExternalStream with + { + Providers = registry, + LeaveStreamOpen = false, + }; // Clone using 'with' expression var clone = original with @@ -533,7 +540,7 @@ public void TarArchive_OpenArchive_UsesCustomGZipProvider() var trackingProvider = new TrackingCompressionProvider(new GZipCompressionProvider()); var registry = CompressionProviderRegistry.Default.With(trackingProvider); - var readOptions = new ReaderOptions { Providers = registry }; + var readOptions = ReaderOptions.ForExternalStream.WithProviders(registry); archiveStream.Position = 0; using var archive = TarArchive.OpenArchive(archiveStream, readOptions); @@ -562,7 +569,7 @@ public async Task TarArchive_OpenAsyncArchive_UsesCustomGZipProvider() var trackingProvider = new TrackingCompressionProvider(new GZipCompressionProvider()); var registry = CompressionProviderRegistry.Default.With(trackingProvider); - var readOptions = new ReaderOptions { Providers = registry }; + var readOptions = ReaderOptions.ForExternalStream.WithProviders(registry); archiveStream.Position = 0; await using var archive = await TarArchive.OpenAsyncArchive(archiveStream, readOptions); @@ -600,7 +607,7 @@ public async Task ZipReader_OpenEntryStreamAsync_UsesCustomDeflateProvider() var trackingProvider = new TrackingCompressionProvider(new DeflateCompressionProvider()); var registry = CompressionProviderRegistry.Default.With(trackingProvider); - var options = new ReaderOptions { Providers = registry }; + var options = ReaderOptions.ForExternalStream.WithProviders(registry); zipStream.Position = 0; await using var reader = await ReaderFactory.OpenAsyncReader(zipStream, options); @@ -618,7 +625,7 @@ public void LzwReader_OpenReader_UsesCustomLzwProvider() var archivePath = Path.Combine(TestBase.TEST_ARCHIVES_PATH, "Tar.tar.Z"); var trackingProvider = new TrackingCompressionProvider(new LzwCompressionProvider()); var registry = CompressionProviderRegistry.Default.With(trackingProvider); - var options = new ReaderOptions { Providers = registry }; + var options = ReaderOptions.ForExternalStream.WithProviders(registry); using var stream = File.OpenRead(archivePath); using var reader = ReaderFactory.OpenReader(stream, options); @@ -809,7 +816,7 @@ public void TarWriter_WithSystemGZipProvider_CreatesReadableArchive() // Read back using internal provider (should be compatible) archiveStream.Position = 0; - var readOptions = new ReaderOptions(); + var readOptions = ReaderOptions.ForExternalStream; using var reader = TarReader.OpenReader(archiveStream, readOptions); reader.MoveToNextEntry().Should().BeTrue(); using var entryStream = reader.OpenEntryStream(); diff --git a/tests/SharpCompress.Test/Lzw/LzwReaderTests.cs b/tests/SharpCompress.Test/Lzw/LzwReaderTests.cs index 8e94481f9..7a74967e2 100644 --- a/tests/SharpCompress.Test/Lzw/LzwReaderTests.cs +++ b/tests/SharpCompress.Test/Lzw/LzwReaderTests.cs @@ -37,7 +37,10 @@ public void Lzw_Reader_Factory_Detects_Tar_Wrapper() using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.Z")); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LeaveStreamOpen = false } + ReaderOptions.ForExternalStream with + { + LeaveStreamOpen = false, + } ); // Should detect as Tar archive with Lzw compression diff --git a/tests/SharpCompress.Test/OptionsUsabilityTests.cs b/tests/SharpCompress.Test/OptionsUsabilityTests.cs index 70b73cb75..f9f05aed5 100644 --- a/tests/SharpCompress.Test/OptionsUsabilityTests.cs +++ b/tests/SharpCompress.Test/OptionsUsabilityTests.cs @@ -160,8 +160,8 @@ public void WriterOptions_Factory_And_Fluent_Equivalent_To_Constructor() [Fact] public void ReaderOptions_Fluent_Methods_Modify_Correctly() { - var options = new ReaderOptions() - .WithLeaveStreamOpen(false) + var options = ReaderOptions + .ForExternalStream.WithLeaveStreamOpen(false) .WithPassword("secret") .WithLookForHeader(true) .WithBufferSize(65536); @@ -176,15 +176,15 @@ public void ReaderOptions_Fluent_Methods_Modify_Correctly() public void ReaderOptions_Fluent_And_Initializer_Equivalent() { // Fluent approach - var fluentApproach = new ReaderOptions() - .WithLeaveStreamOpen(false) + var fluentApproach = ReaderOptions + .ForExternalStream.WithLeaveStreamOpen(false) .WithPassword("secret") .WithLookForHeader(true) .WithBufferSize(65536) .WithDisableCheckIncomplete(true); - // Object initializer approach - var initializerApproach = new ReaderOptions + // Preset + with-expression approach + var initializerApproach = ReaderOptions.ForExternalStream with { LeaveStreamOpen = false, Password = "secret", diff --git a/tests/SharpCompress.Test/ProgressReportTests.cs b/tests/SharpCompress.Test/ProgressReportTests.cs index a26e96cd9..ff79a41cc 100644 --- a/tests/SharpCompress.Test/ProgressReportTests.cs +++ b/tests/SharpCompress.Test/ProgressReportTests.cs @@ -108,7 +108,7 @@ public void Zip_Read_ReportsProgress() // Now read it with progress reporting archiveStream.Position = 0; - var readerOptions = new ReaderOptions { Progress = progress }; + var readerOptions = ReaderOptions.ForExternalStream.WithProgress(progress); using (var reader = ReaderFactory.OpenReader(archiveStream, readerOptions)) { @@ -234,7 +234,7 @@ public void ReaderOptions_WithoutProgress_DoesNotThrow() // Read without progress archiveStream.Position = 0; - var readerOptions = new ReaderOptions(); + var readerOptions = ReaderOptions.ForExternalStream; Assert.Null(readerOptions.Progress); using (var reader = ReaderFactory.OpenReader(archiveStream, readerOptions)) @@ -324,7 +324,7 @@ public void Tar_Read_ReportsProgress() // Now read it with progress reporting archiveStream.Position = 0; - var readerOptions = new ReaderOptions { Progress = progress }; + var readerOptions = ReaderOptions.ForExternalStream.WithProgress(progress); using (var reader = ReaderFactory.OpenReader(archiveStream, readerOptions)) { @@ -445,7 +445,7 @@ public void Zip_Read_MultipleEntries_ReportsProgress() // Now read it with progress reporting archiveStream.Position = 0; - var readerOptions = new ReaderOptions { Progress = progress }; + var readerOptions = ReaderOptions.ForExternalStream.WithProgress(progress); using (var reader = ReaderFactory.OpenReader(archiveStream, readerOptions)) { @@ -538,7 +538,7 @@ public async ValueTask Zip_ReadAsync_ReportsProgress() // Now read it with progress reporting archiveStream.Position = 0; - var readerOptions = new ReaderOptions { Progress = progress }; + var readerOptions = ReaderOptions.ForExternalStream.WithProgress(progress); await using ( var reader = await ReaderFactory.OpenAsyncReader( diff --git a/tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs index 3f48b9765..eebdd38d6 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs @@ -71,7 +71,11 @@ private async ValueTask ReadRarPasswordAsync(string testArchive, string? passwor await using ( var archive = await RarArchive.OpenAsyncArchive( stream, - new ReaderOptions { Password = password, LeaveStreamOpen = true } + ReaderOptions.ForExternalStream with + { + Password = password, + LeaveStreamOpen = true, + } ) ) { @@ -98,7 +102,11 @@ protected async Task ArchiveFileReadPasswordAsync(string archiveName, string pas using ( var archive = RarArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, archiveName), - new ReaderOptions { Password = password, LeaveStreamOpen = true } + ReaderOptions.ForFilePath with + { + Password = password, + LeaveStreamOpen = true, + } ) ) { @@ -144,7 +152,13 @@ public async ValueTask Rar_Jpg_ArchiveStreamRead_Async() { using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg")); using ( - var archive = RarArchive.OpenArchive(stream, new ReaderOptions { LookForHeader = true }) + var archive = RarArchive.OpenArchive( + stream, + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } + ) ) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) @@ -316,7 +330,10 @@ public async ValueTask Rar_Jpg_ArchiveFileRead_Async() using ( var archive = RarArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForFilePath with + { + LookForHeader = true, + } ) ) { diff --git a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs index fdb8d56bc..20b5faa01 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -66,7 +66,11 @@ private void ReadRarPassword(string testArchive, string? password) using ( var archive = RarArchive.OpenArchive( stream, - new ReaderOptions { Password = password, LeaveStreamOpen = true } + ReaderOptions.ForExternalStream with + { + Password = password, + LeaveStreamOpen = true, + } ) ) { @@ -93,7 +97,11 @@ protected void ArchiveFileReadPassword(string archiveName, string password) using ( var archive = RarArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, archiveName), - new ReaderOptions { Password = password, LeaveStreamOpen = true } + ReaderOptions.ForFilePath with + { + Password = password, + LeaveStreamOpen = true, + } ) ) { @@ -136,7 +144,13 @@ public void Rar_Jpg_ArchiveStreamRead() { using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg")); using ( - var archive = RarArchive.OpenArchive(stream, new ReaderOptions { LookForHeader = true }) + var archive = RarArchive.OpenArchive( + stream, + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } + ) ) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) @@ -302,7 +316,10 @@ public void Rar_Jpg_ArchiveFileRead() using ( var archive = RarArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForFilePath with + { + LookForHeader = true, + } ) ) { @@ -751,7 +768,7 @@ public void Rar_Issue1050_WriteToDirectory_ExtractsToSubdirectories() public void Rar_MalformedArchive_NoInfiniteLoop() { var testFile = "Rar.malformed_512byte.rar"; - var readerOptions = new ReaderOptions { LookForHeader = true }; + var readerOptions = ReaderOptions.ForExternalStream.WithLookForHeader(true); // This should throw InvalidOperationException, not hang in an infinite loop var exception = Assert.Throws(() => diff --git a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs index 70015fcfa..6fd42ba9b 100644 --- a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs +++ b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs @@ -16,7 +16,10 @@ public class RarHeaderFactoryTest : TestBase public RarHeaderFactoryTest() => _rarHeaderFactory = new RarHeaderFactory( StreamingMode.Seekable, - new ReaderOptions { LeaveStreamOpen = true } + ReaderOptions.ForExternalStream with + { + LeaveStreamOpen = true, + } ); [Fact] diff --git a/tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs b/tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs index d6d82e261..188784c53 100644 --- a/tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs +++ b/tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs @@ -73,7 +73,10 @@ await Assert.ThrowsAsync(async () => archives .Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) .Select(p => File.OpenRead(p)), - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { @@ -187,7 +190,10 @@ private async ValueTask ReadRar_Async(string testArchive, string password) => await ReadAsync( testArchive, CompressionType.Rar, - new ReaderOptions { Password = password } + ReaderOptions.ForFilePath with + { + Password = password, + } ); [Fact] @@ -248,7 +254,10 @@ public async ValueTask Rar_Reader_Audio_program_Async() await using ( var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ) ) { @@ -271,7 +280,10 @@ public async ValueTask Rar_Jpg_Reader_Async() using ( IReader baseReader = RarReader.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ) ) { @@ -314,7 +326,10 @@ private async ValueTask DoRar_Solid_Skip_Reader_Async(string filename) using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (await reader.MoveToNextEntryAsync()) { @@ -337,7 +352,10 @@ private async ValueTask DoRar_Reader_Skip_Async(string filename) using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (await reader.MoveToNextEntryAsync()) { @@ -359,7 +377,7 @@ private async ValueTask ReadAsync( using Stream stream = File.OpenRead(testArchive); await using var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - readerOptions ?? new ReaderOptions() + readerOptions ?? ReaderOptions.ForExternalStream ); while (await reader.MoveToNextEntryAsync()) { diff --git a/tests/SharpCompress.Test/Rar/RarReaderTests.cs b/tests/SharpCompress.Test/Rar/RarReaderTests.cs index 008db7fd1..a037f9bbf 100644 --- a/tests/SharpCompress.Test/Rar/RarReaderTests.cs +++ b/tests/SharpCompress.Test/Rar/RarReaderTests.cs @@ -71,7 +71,10 @@ private void DoRar_Multi_Reader_Encrypted(string[] archives) => archives .Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) .Select(p => File.OpenRead(p)), - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { @@ -173,7 +176,14 @@ public void Rar5_EncryptedFileAndHeader_Reader() => public void Rar5_Encrypted_Reader() => ReadRar("Rar5.encrypted_filesOnly.rar", "test"); private void ReadRar(string testArchive, string password) => - Read(testArchive, CompressionType.Rar, new ReaderOptions { Password = password }); + Read( + testArchive, + CompressionType.Rar, + ReaderOptions.ForFilePath with + { + Password = password, + } + ); [Fact] public void Rar_Entry_Stream() => DoRar_Entry_Stream("Rar.rar"); @@ -222,7 +232,10 @@ public void Rar_Reader_Audio_program() using ( var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ) ) { @@ -243,7 +256,13 @@ public void Rar_Jpg_Reader() { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"))) using ( - var reader = RarReader.OpenReader(stream, new ReaderOptions { LookForHeader = true }) + var reader = RarReader.OpenReader( + stream, + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } + ) ) { while (reader.MoveToNextEntry()) @@ -278,7 +297,10 @@ private void DoRar_Solid_Skip_Reader(string filename) using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (reader.MoveToNextEntry()) { @@ -301,7 +323,10 @@ private void DoRar_Reader_Skip(string filename) using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename)); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (reader.MoveToNextEntry()) { @@ -321,7 +346,10 @@ public void Rar_SkipEncryptedFilesWithoutPassword() ); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (reader.MoveToNextEntry()) { diff --git a/tests/SharpCompress.Test/ReaderTests.cs b/tests/SharpCompress.Test/ReaderTests.cs index e4fedc587..72ab5f47e 100644 --- a/tests/SharpCompress.Test/ReaderTests.cs +++ b/tests/SharpCompress.Test/ReaderTests.cs @@ -32,12 +32,12 @@ Action readImpl ) { testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive); - options ??= new ReaderOptions { BufferSize = 0x20000 }; + options ??= ReaderOptions.ForFilePath.WithBufferSize(0x20000); - var optionsWithStreamOpen = options with { LeaveStreamOpen = true }; + var optionsWithStreamOpen = options.WithLeaveStreamOpen(true); readImpl(testArchive, optionsWithStreamOpen); - var optionsWithStreamClosed = options with { LeaveStreamOpen = false }; + var optionsWithStreamClosed = options.WithLeaveStreamOpen(false); readImpl(testArchive, optionsWithStreamClosed); VerifyFiles(); @@ -128,9 +128,9 @@ protected async Task ReadAsync( { testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive); - options ??= new ReaderOptions() { BufferSize = 0x20000 }; + options ??= ReaderOptions.ForExternalStream.WithBufferSize(0x20000); - var optionsWithStreamOpen = options with { LeaveStreamOpen = true }; + var optionsWithStreamOpen = options.WithLeaveStreamOpen(true); await ReadImplAsync( testArchive, expectedCompression, @@ -138,7 +138,7 @@ await ReadImplAsync( cancellationToken ); - var optionsWithStreamClosed = options with { LeaveStreamOpen = false }; + var optionsWithStreamClosed = options.WithLeaveStreamOpen(false); await ReadImplAsync( testArchive, expectedCompression, @@ -215,7 +215,10 @@ protected void ReadForBufferBoundaryCheck(string fileName, CompressionType compr using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, fileName)); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LookForHeader = true } + ReaderOptions.ForExternalStream with + { + LookForHeader = true, + } ); while (reader.MoveToNextEntry()) diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index ccb3596eb..e3016d964 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -27,16 +27,28 @@ public class SevenZipArchiveTests : ArchiveTests [Fact] public void SevenZipArchive_LZMAAES_StreamRead() => - ArchiveStreamRead("7Zip.LZMA.Aes.7z", new ReaderOptions { Password = "testpassword" }); + ArchiveStreamRead( + "7Zip.LZMA.Aes.7z", + ReaderOptions.ForExternalStream with + { + Password = "testpassword", + } + ); [Fact] public void SevenZipArchive_LZMAAES_PathRead() => - ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions { Password = "testpassword" }); + ArchiveFileRead( + "7Zip.LZMA.Aes.7z", + ReaderOptions.ForFilePath with + { + Password = "testpassword", + } + ); [Fact] public void SevenZipArchive_LZMAAES_NoPasswordExceptionTest() => Assert.Throws(() => - ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions { Password = null }) + ArchiveFileRead("7Zip.LZMA.Aes.7z", ReaderOptions.ForFilePath.WithPassword(null)) ); //was failing with ArgumentNullException not CryptographicException like rar [Fact] @@ -57,19 +69,39 @@ public void SevenZipArchive_PPMd_StreamRead_Extract_All() => [Fact] public void SevenZipArchive_LZMA2_EXE_StreamRead() => - ArchiveStreamRead(new SevenZipFactory(), "7Zip.LZMA2.exe", new() { LookForHeader = true }); + ArchiveStreamRead( + new SevenZipFactory(), + "7Zip.LZMA2.exe", + ReaderOptions.ForExternalStream.WithLookForHeader(true) + ); [Fact] public void SevenZipArchive_LZMA2_EXE_PathRead() => - ArchiveFileRead("7Zip.LZMA2.exe", new() { LookForHeader = true }, new SevenZipFactory()); + ArchiveFileRead( + "7Zip.LZMA2.exe", + ReaderOptions.ForFilePath.WithLookForHeader(true), + new SevenZipFactory() + ); [Fact] public void SevenZipArchive_LZMA2AES_StreamRead() => - ArchiveStreamRead("7Zip.LZMA2.Aes.7z", new ReaderOptions { Password = "testpassword" }); + ArchiveStreamRead( + "7Zip.LZMA2.Aes.7z", + ReaderOptions.ForExternalStream with + { + Password = "testpassword", + } + ); [Fact] public void SevenZipArchive_LZMA2AES_PathRead() => - ArchiveFileRead("7Zip.LZMA2.Aes.7z", new ReaderOptions { Password = "testpassword" }); + ArchiveFileRead( + "7Zip.LZMA2.Aes.7z", + ReaderOptions.ForFilePath with + { + Password = "testpassword", + } + ); [Fact] public void SevenZipArchive_BZip2_StreamRead() => ArchiveStreamRead("7Zip.BZip2.7z"); diff --git a/tests/SharpCompress.Test/Streams/DisposalTests.cs b/tests/SharpCompress.Test/Streams/DisposalTests.cs index 75d6c69e3..b80d69434 100644 --- a/tests/SharpCompress.Test/Streams/DisposalTests.cs +++ b/tests/SharpCompress.Test/Streams/DisposalTests.cs @@ -76,7 +76,10 @@ public void SourceStream_Disposal() new SourceStream( stream, i => null, - new ReaderOptions { LeaveStreamOpen = leaveOpen } + ReaderOptions.ForExternalStream with + { + LeaveStreamOpen = leaveOpen, + } ) ); } diff --git a/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs index b9b7d6eb3..30b511fae 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs @@ -57,7 +57,7 @@ public async ValueTask Tar_FileName_Exactly_100_Characters_Async() await using ( var archive2 = await TarArchive.OpenAsyncArchive( new AsyncOnlyStream(File.OpenRead(unmodified)), - new ReaderOptions() { LeaveStreamOpen = false } + ReaderOptions.ForExternalStream.WithLeaveStreamOpen(false) ) ) { @@ -115,7 +115,7 @@ public async ValueTask Tar_VeryLongFilepathReadback_Async() await using ( var archive2 = await TarArchive.OpenAsyncArchive( new AsyncOnlyStream(File.OpenRead(unmodified)), - new ReaderOptions() { LeaveStreamOpen = false } + ReaderOptions.ForExternalStream.WithLeaveStreamOpen(false) ) ) { @@ -213,7 +213,7 @@ public async ValueTask Tar_Japanese_Name_Async(int length) } using (var inputMemory = new MemoryStream(mstm.ToArray())) { - var tropt = new ReaderOptions { ArchiveEncoding = enc }; + var tropt = ReaderOptions.ForExternalStream.WithArchiveEncoding(enc); await using ( var tr = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(inputMemory), diff --git a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs index 086ca02c0..ebb721f5a 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs @@ -262,7 +262,7 @@ public void Tar_Japanese_Name(int length) } using (var inputMemory = new MemoryStream(mstm.ToArray())) { - var tropt = new ReaderOptions { ArchiveEncoding = enc }; + var tropt = ReaderOptions.ForExternalStream.WithArchiveEncoding(enc); using (var tr = TarReader.OpenReader(inputMemory, tropt)) { while (tr.MoveToNextEntry()) diff --git a/tests/SharpCompress.Test/TestBase.cs b/tests/SharpCompress.Test/TestBase.cs index 1b4656d6a..0cdd6a071 100644 --- a/tests/SharpCompress.Test/TestBase.cs +++ b/tests/SharpCompress.Test/TestBase.cs @@ -255,7 +255,7 @@ private void CompareFilesByTimeAndAttribute(string file1, string file2) protected void CompareArchivesByPath(string file1, string file2, Encoding? encoding = null) { - var readerOptions = new ReaderOptions { LeaveStreamOpen = false }; + var readerOptions = ReaderOptions.ForExternalStream.WithLeaveStreamOpen(false); readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; //don't compare the order. OS X reads files from the file system in a different order therefore makes the archive ordering different diff --git a/tests/SharpCompress.Test/WriterTests.cs b/tests/SharpCompress.Test/WriterTests.cs index 25f6e4068..1142f7acd 100644 --- a/tests/SharpCompress.Test/WriterTests.cs +++ b/tests/SharpCompress.Test/WriterTests.cs @@ -39,7 +39,7 @@ protected void Write( using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive))) { - var readerOptions = new ReaderOptions(); + var readerOptions = ReaderOptions.ForExternalStream; readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; @@ -90,7 +90,7 @@ await writer.WriteAllAsync( using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive))) { - var readerOptions = new ReaderOptions(); + var readerOptions = ReaderOptions.ForExternalStream; readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; diff --git a/tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs b/tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs index 2d7a0c7b3..32e666b43 100644 --- a/tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs +++ b/tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs @@ -201,7 +201,10 @@ public async ValueTask> ReadForwardOnlyAsync(string filename) { await using var rd = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(fs), - new ReaderOptions { LookForHeader = false } + ReaderOptions.ForExternalStream with + { + LookForHeader = false, + } ); while (await rd.MoveToNextEntryAsync()) { diff --git a/tests/SharpCompress.Test/Zip/Zip64Tests.cs b/tests/SharpCompress.Test/Zip/Zip64Tests.cs index 68d27625b..e1bac5bd3 100644 --- a/tests/SharpCompress.Test/Zip/Zip64Tests.cs +++ b/tests/SharpCompress.Test/Zip/Zip64Tests.cs @@ -182,7 +182,15 @@ public Tuple ReadForwardOnly(string filename) long size = 0; IEntry? prev = null; using (var fs = File.OpenRead(filename)) - using (var rd = ZipReader.OpenReader(fs, new ReaderOptions { LookForHeader = false })) + using ( + var rd = ZipReader.OpenReader( + fs, + ReaderOptions.ForExternalStream with + { + LookForHeader = false, + } + ) + ) { while (rd.MoveToNextEntry()) { diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index 92073da41..82192b224 100644 --- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -465,7 +465,10 @@ public void Zip_Deflate_WinzipAES_Read() using ( var reader = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ) ) { @@ -482,7 +485,10 @@ public void Zip_Deflate_WinzipAES_MultiOpenEntryStream() { using var reader = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES2.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); foreach (var entry in reader.Entries.Where(x => !x.IsDirectory)) { @@ -499,7 +505,10 @@ public void Zip_WinzipAES_CompressionType() // Test that WinZip AES encrypted entries correctly report their compression type using var deflateArchive = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); foreach (var entry in deflateArchive.Entries.Where(x => !x.IsDirectory)) { @@ -509,7 +518,10 @@ public void Zip_WinzipAES_CompressionType() using var lzmaArchive = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.lzma.WinzipAES.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); foreach (var entry in lzmaArchive.Entries.Where(x => !x.IsDirectory)) { @@ -523,7 +535,10 @@ public void Zip_Zstandard_WinzipAES_Mixed_ArchiveFileRead() { using var archive = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.zstd.WinzipAES.mixed.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); VerifyMixedZstandardArchive(archive); @@ -535,7 +550,13 @@ public void Zip_Zstandard_WinzipAES_Mixed_ArchiveStreamRead() using var stream = File.OpenRead( Path.Combine(TEST_ARCHIVES_PATH, "Zip.zstd.WinzipAES.mixed.zip") ); - using var archive = ZipArchive.OpenArchive(stream, new ReaderOptions { Password = "test" }); + using var archive = ZipArchive.OpenArchive( + stream, + ReaderOptions.ForExternalStream with + { + Password = "test", + } + ); VerifyMixedZstandardArchive(archive); } @@ -571,7 +592,10 @@ public void Zip_Pkware_CompressionType() // Test that Pkware encrypted entries correctly report their compression type using var deflateArchive = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.pkware.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); foreach (var entry in deflateArchive.Entries.Where(x => !x.IsDirectory)) { @@ -581,7 +605,10 @@ public void Zip_Pkware_CompressionType() using var bzip2Archive = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); foreach (var entry in bzip2Archive.Entries.Where(x => !x.IsDirectory)) { @@ -595,7 +622,10 @@ public void Zip_Read_Volume_Comment() { using var reader = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.zip64.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); var isComplete = reader.IsComplete; Assert.Equal(1, reader.Volumes.Count()); @@ -611,7 +641,10 @@ public void Zip_BZip2_Pkware_Read() using ( var reader = ZipArchive.OpenArchive( Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ) ) { @@ -673,7 +706,10 @@ public void Zip_Deflate_PKWear_Multipy_Entry_Access() using var fileStream = File.OpenRead(zipFile); using var archive = ArchiveFactory.OpenArchive( fileStream, - new ReaderOptions { Password = "12345678" } + ReaderOptions.ForExternalStream with + { + Password = "12345678", + } ); var entries = archive.Entries.Where(entry => !entry.IsDirectory); foreach (var entry in entries) @@ -881,7 +917,7 @@ public void Zip_Forced_Ignores_UnicodePathExtra() { var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions + ReaderOptions.ForExternalStream with { ArchiveEncoding = new ArchiveEncoding { @@ -896,7 +932,7 @@ public void Zip_Forced_Ignores_UnicodePathExtra() { var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions + ReaderOptions.ForExternalStream with { ArchiveEncoding = new ArchiveEncoding { diff --git a/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs index a9525ede2..4c7cd6270 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs @@ -143,7 +143,10 @@ public async ValueTask Zip_BZip2_PkwareEncryption_Read_Async() using ( IReader baseReader = ZipReader.OpenReader( stream, - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { @@ -169,7 +172,7 @@ public async ValueTask Zip_Reader_Disposal_Test_Async() await using ( var reader = await ReaderFactory.OpenAsyncReader( new AsyncOnlyStream(stream), - new ReaderOptions().WithLeaveStreamOpen(false) + ReaderOptions.ForExternalStream.WithLeaveStreamOpen(false) ) ) { @@ -215,7 +218,10 @@ await Assert.ThrowsAsync(async () => using ( IReader baseReader = ZipReader.OpenReader( stream, - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { @@ -244,7 +250,10 @@ public async ValueTask Zip_Deflate_WinzipAES_Read_Async() await using ( var reader = await ReaderFactory.OpenAsyncReader( stream, - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { @@ -272,7 +281,10 @@ public async ValueTask Zip_Deflate_ZipCrypto_Read_Async() await using ( var reader = await ReaderFactory.OpenAsyncReader( stream, - new ReaderOptions { Password = "test" } + ReaderOptions.ForExternalStream with + { + Password = "test", + } ) ) { diff --git a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs index af4bd3ad5..473c862ee 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -129,7 +129,15 @@ public void Zip_BZip2_PkwareEncryption_Read() using ( Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip")) ) - using (var reader = ZipReader.OpenReader(stream, new ReaderOptions { Password = "test" })) + using ( + var reader = ZipReader.OpenReader( + stream, + ReaderOptions.ForExternalStream with + { + Password = "test", + } + ) + ) { while (reader.MoveToNextEntry()) { @@ -152,7 +160,7 @@ public void Zip_Reader_Disposal_Test() using ( var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions().WithLeaveStreamOpen(false) + ReaderOptions.ForExternalStream.WithLeaveStreamOpen(false) ) ) { @@ -194,7 +202,13 @@ public void Zip_LZMA_WinzipAES_Read() => ) ) using ( - var reader = ZipReader.OpenReader(stream, new ReaderOptions { Password = "test" }) + var reader = ZipReader.OpenReader( + stream, + ReaderOptions.ForExternalStream with + { + Password = "test", + } + ) ) { while (reader.MoveToNextEntry()) @@ -217,7 +231,15 @@ public void Zip_Deflate_WinzipAES_Read() Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip") ) ) - using (var reader = ZipReader.OpenReader(stream, new ReaderOptions { Password = "test" })) + using ( + var reader = ZipReader.OpenReader( + stream, + ReaderOptions.ForExternalStream with + { + Password = "test", + } + ) + ) { while (reader.MoveToNextEntry()) { @@ -236,7 +258,15 @@ public void Zip_Deflate_ZipCrypto_Read() { var count = 0; using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "zipcrypto.zip"))) - using (var reader = ZipReader.OpenReader(stream, new ReaderOptions { Password = "test" })) + using ( + var reader = ZipReader.OpenReader( + stream, + ReaderOptions.ForExternalStream with + { + Password = "test", + } + ) + ) { while (reader.MoveToNextEntry()) { @@ -402,7 +432,10 @@ public void Zip_Uncompressed_Encrypted_Read() { using var reader = ReaderFactory.OpenReader( Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.encrypted.zip"), - new ReaderOptions { Password = "test" } + ReaderOptions.ForFilePath with + { + Password = "test", + } ); reader.MoveToNextEntry(); Assert.Equal("first.txt", reader.Entry.Key); diff --git a/tests/SharpCompress.Test/Zip/ZipShortReadTests.cs b/tests/SharpCompress.Test/Zip/ZipShortReadTests.cs index 34c2777b1..f9f1d72a1 100644 --- a/tests/SharpCompress.Test/Zip/ZipShortReadTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipShortReadTests.cs @@ -99,7 +99,10 @@ private List ReadEntriesFromStream(Stream stream) var names = new List(); using var reader = ReaderFactory.OpenReader( stream, - new ReaderOptions { LeaveStreamOpen = true } + ReaderOptions.ForExternalStream with + { + LeaveStreamOpen = true, + } ); while (reader.MoveToNextEntry())