diff --git a/src/SharpCompress/Archives/ArchiveFactory.Async.cs b/src/SharpCompress/Archives/ArchiveFactory.Async.cs index de357c506..8e5f7d90a 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.Async.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.Async.cs @@ -77,7 +77,9 @@ public static async ValueTask OpenAsyncArchive( var factory = await FindFactoryAsync(fileInfo, cancellationToken) .ConfigureAwait(false); - return factory.OpenAsyncArchive(filesArray, options); + return await factory + .OpenAsyncArchive(filesArray, options, cancellationToken) + .ConfigureAwait(false); } public static async ValueTask OpenAsyncArchive( @@ -106,7 +108,9 @@ public static async ValueTask OpenAsyncArchive( var factory = await FindFactoryAsync(firstStream, cancellationToken) .ConfigureAwait(false); - return factory.OpenAsyncArchive(streamsArray, options); + return await factory + .OpenAsyncArchive(streamsArray, options, cancellationToken) + .ConfigureAwait(false); } public static ValueTask FindFactoryAsync( diff --git a/src/SharpCompress/Archives/IMultiArchiveFactory.cs b/src/SharpCompress/Archives/IMultiArchiveFactory.cs index 936222e6f..3f9e0ec11 100644 --- a/src/SharpCompress/Archives/IMultiArchiveFactory.cs +++ b/src/SharpCompress/Archives/IMultiArchiveFactory.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Threading; +using System.Threading.Tasks; using SharpCompress.Factories; using SharpCompress.Readers; @@ -33,9 +34,12 @@ public interface IMultiArchiveFactory : IFactory /// /// /// reading options. - IAsyncArchive OpenAsyncArchive( + /// Cancellation token. + /// A containing the opened async archive. + ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default ); /// @@ -50,8 +54,11 @@ IAsyncArchive OpenAsyncArchive( /// /// /// reading options. - IAsyncArchive OpenAsyncArchive( + /// Cancellation token. + /// A containing the opened async archive. + ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default ); } diff --git a/src/SharpCompress/Factories/GZipFactory.cs b/src/SharpCompress/Factories/GZipFactory.cs index e4062e62a..70a2ad85d 100644 --- a/src/SharpCompress/Factories/GZipFactory.cs +++ b/src/SharpCompress/Factories/GZipFactory.cs @@ -95,10 +95,17 @@ public IArchive OpenArchive( ) => GZipArchive.OpenArchive(streams, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(streams, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await GZipArchive + .OpenAsyncArchive(streams, readerOptions, cancellationToken) + .ConfigureAwait(false); + } /// public IArchive OpenArchive( @@ -107,10 +114,17 @@ public IArchive OpenArchive( ) => GZipArchive.OpenArchive(fileInfos, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(fileInfos, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await GZipArchive + .OpenAsyncArchive(fileInfos, readerOptions, cancellationToken) + .ConfigureAwait(false); + } #endregion @@ -191,14 +205,15 @@ public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions) } /// - public IAsyncWriter OpenAsyncWriter( + public ValueTask OpenAsyncWriter( Stream stream, IWriterOptions writerOptions, CancellationToken cancellationToken = default ) { cancellationToken.ThrowIfCancellationRequested(); - return (IAsyncWriter)OpenWriter(stream, writerOptions); + var writer = OpenWriter(stream, writerOptions); + return new((IAsyncWriter)writer); } #endregion diff --git a/src/SharpCompress/Factories/RarFactory.cs b/src/SharpCompress/Factories/RarFactory.cs index c81e54a78..615f7fb4f 100644 --- a/src/SharpCompress/Factories/RarFactory.cs +++ b/src/SharpCompress/Factories/RarFactory.cs @@ -90,10 +90,17 @@ public IArchive OpenArchive( ) => RarArchive.OpenArchive(streams, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(streams, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await RarArchive + .OpenAsyncArchive(streams, readerOptions, cancellationToken) + .ConfigureAwait(false); + } /// public IArchive OpenArchive( @@ -102,12 +109,16 @@ public IArchive OpenArchive( ) => RarArchive.OpenArchive(fileInfos, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default ) { - return (IAsyncArchive)OpenArchive(fileInfos, readerOptions); + cancellationToken.ThrowIfCancellationRequested(); + return await RarArchive + .OpenAsyncArchive(fileInfos, readerOptions, cancellationToken) + .ConfigureAwait(false); } #endregion diff --git a/src/SharpCompress/Factories/SevenZipFactory.cs b/src/SharpCompress/Factories/SevenZipFactory.cs index 93826468e..e4942041d 100644 --- a/src/SharpCompress/Factories/SevenZipFactory.cs +++ b/src/SharpCompress/Factories/SevenZipFactory.cs @@ -85,10 +85,17 @@ public IArchive OpenArchive( ) => SevenZipArchive.OpenArchive(streams, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(streams, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await SevenZipArchive + .OpenAsyncArchive(streams, readerOptions, cancellationToken) + .ConfigureAwait(false); + } /// public IArchive OpenArchive( @@ -97,10 +104,17 @@ public IArchive OpenArchive( ) => SevenZipArchive.OpenArchive(fileInfos, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(fileInfos, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await SevenZipArchive + .OpenAsyncArchive(fileInfos, readerOptions, cancellationToken) + .ConfigureAwait(false); + } #endregion diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index 32014744a..c92501bac 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -279,10 +279,17 @@ public IArchive OpenArchive( ) => TarArchive.OpenArchive(streams, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(streams, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await TarArchive + .OpenAsyncArchive(streams, readerOptions, cancellationToken) + .ConfigureAwait(false); + } /// public IArchive OpenArchive( @@ -291,10 +298,17 @@ public IArchive OpenArchive( ) => TarArchive.OpenArchive(fileInfos, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(fileInfos, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await TarArchive + .OpenAsyncArchive(fileInfos, readerOptions, cancellationToken) + .ConfigureAwait(false); + } #endregion @@ -394,14 +408,15 @@ public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions) } /// - public IAsyncWriter OpenAsyncWriter( + public ValueTask OpenAsyncWriter( Stream stream, IWriterOptions writerOptions, CancellationToken cancellationToken = default ) { cancellationToken.ThrowIfCancellationRequested(); - return (IAsyncWriter)OpenWriter(stream, writerOptions); + var writer = OpenWriter(stream, writerOptions); + return new((IAsyncWriter)writer); } #endregion diff --git a/src/SharpCompress/Factories/ZipFactory.cs b/src/SharpCompress/Factories/ZipFactory.cs index 6c683a38f..057bfb658 100644 --- a/src/SharpCompress/Factories/ZipFactory.cs +++ b/src/SharpCompress/Factories/ZipFactory.cs @@ -163,10 +163,17 @@ public IArchive OpenArchive( ) => ZipArchive.OpenArchive(streams, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList streams, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(streams, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await ZipArchive + .OpenAsyncArchive(streams, readerOptions, cancellationToken) + .ConfigureAwait(false); + } /// public IArchive OpenArchive( @@ -175,10 +182,17 @@ public IArchive OpenArchive( ) => ZipArchive.OpenArchive(fileInfos, readerOptions); /// - public IAsyncArchive OpenAsyncArchive( + public async ValueTask OpenAsyncArchive( IReadOnlyList fileInfos, - ReaderOptions? readerOptions = null - ) => (IAsyncArchive)OpenArchive(fileInfos, readerOptions); + ReaderOptions? readerOptions = null, + CancellationToken cancellationToken = default + ) + { + cancellationToken.ThrowIfCancellationRequested(); + return await ZipArchive + .OpenAsyncArchive(fileInfos, readerOptions, cancellationToken) + .ConfigureAwait(false); + } #endregion @@ -219,14 +233,15 @@ public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions) } /// - public IAsyncWriter OpenAsyncWriter( + public ValueTask OpenAsyncWriter( Stream stream, IWriterOptions writerOptions, CancellationToken cancellationToken = default ) { cancellationToken.ThrowIfCancellationRequested(); - return (IAsyncWriter)OpenWriter(stream, writerOptions); + var writer = OpenWriter(stream, writerOptions); + return new((IAsyncWriter)writer); } #endregion diff --git a/src/SharpCompress/Readers/ReaderFactory.Async.cs b/src/SharpCompress/Readers/ReaderFactory.Async.cs index 1bed74d5f..e3f3a4be3 100644 --- a/src/SharpCompress/Readers/ReaderFactory.Async.cs +++ b/src/SharpCompress/Readers/ReaderFactory.Async.cs @@ -35,14 +35,15 @@ public static ValueTask OpenAsyncReader( /// /// /// - public static ValueTask OpenAsyncReader( + public static async ValueTask OpenAsyncReader( FileInfo fileInfo, ReaderOptions? options = null, CancellationToken cancellationToken = default ) { options ??= ReaderOptions.ForOwnedFile; - return OpenAsyncReader(fileInfo.OpenRead(), options, cancellationToken); + var stream = fileInfo.OpenAsyncReadStream(cancellationToken); + return await OpenAsyncReader(stream, options, cancellationToken).ConfigureAwait(false); } public static async ValueTask OpenAsyncReader( diff --git a/src/SharpCompress/Readers/Tar/TarReader.Factory.cs b/src/SharpCompress/Readers/Tar/TarReader.Factory.cs index 2bb9d8496..13c8453cd 100644 --- a/src/SharpCompress/Readers/Tar/TarReader.Factory.cs +++ b/src/SharpCompress/Readers/Tar/TarReader.Factory.cs @@ -133,14 +133,16 @@ await TarArchive.IsTarFileAsync(testStream, cancellationToken).ConfigureAwait(fa return new TarReader(sharpCompressStream, readerOptions, CompressionType.None); } - public static ValueTask OpenAsyncReader( + public static async ValueTask OpenAsyncReader( FileInfo fileInfo, ReaderOptions? readerOptions = null, CancellationToken cancellationToken = default ) { readerOptions ??= new ReaderOptions() { LeaveStreamOpen = false }; - return OpenAsyncReader(fileInfo.OpenRead(), readerOptions, cancellationToken); + var stream = fileInfo.OpenAsyncReadStream(cancellationToken); + return await OpenAsyncReader(stream, readerOptions, cancellationToken) + .ConfigureAwait(false); } public static IReader OpenReader(string filePath, ReaderOptions? readerOptions = null) diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index bf8579ac3..7cf1686ab 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -31,7 +31,7 @@ $(DefineConstants);LEGACY_DOTNET - + true true diff --git a/src/SharpCompress/Utility.Async.cs b/src/SharpCompress/Utility.Async.cs index 60f520687..f717eb312 100644 --- a/src/SharpCompress/Utility.Async.cs +++ b/src/SharpCompress/Utility.Async.cs @@ -120,4 +120,108 @@ public async ValueTask ReadFullyAsync( return (total >= count); } } + + /// + /// Opens a file stream for asynchronous writing. + /// Uses File.OpenHandle with FileOptions.Asynchronous on .NET 8.0+ for optimal performance. + /// Falls back to FileStream constructor with async options on legacy frameworks. + /// + /// The file path to open. + /// Cancellation token. + /// A FileStream configured for asynchronous operations. + public static Stream OpenAsyncWriteStream(string path, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + +#if NET8_0_OR_GREATER + // Use File.OpenHandle with async options for .NET 8.0+ + var handle = File.OpenHandle( + path, + FileMode.Create, + FileAccess.Write, + FileShare.None, + FileOptions.Asynchronous + ); + return new FileStream(handle, FileAccess.Write); +#else + // For older target frameworks, use FileStream constructor with async options + return new FileStream( + path, + FileMode.Create, + FileAccess.Write, + FileShare.None, + bufferSize: 4096, //default + FileOptions.Asynchronous + ); +#endif + } + + /// + /// Opens a file stream for asynchronous writing from a FileInfo. + /// Uses File.OpenHandle with FileOptions.Asynchronous on .NET 8.0+ for optimal performance. + /// Falls back to FileStream constructor with async options on legacy frameworks. + /// + /// The FileInfo to open. + /// Cancellation token. + /// A FileStream configured for asynchronous operations. + public static Stream OpenAsyncWriteStream( + this FileInfo fileInfo, + CancellationToken cancellationToken + ) + { + fileInfo.NotNull(nameof(fileInfo)); + return OpenAsyncWriteStream(fileInfo.FullName, cancellationToken); + } + + /// + /// Opens a file stream for asynchronous reading. + /// Uses File.OpenHandle with FileOptions.Asynchronous on .NET 8.0+ for optimal performance. + /// Falls back to FileStream constructor with async options on legacy frameworks. + /// + /// The file path to open. + /// Cancellation token. + /// A FileStream configured for asynchronous operations. + public static Stream OpenAsyncReadStream(string path, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + +#if NET8_0_OR_GREATER + // Use File.OpenHandle with async options for .NET 8.0+ + var handle = File.OpenHandle( + path, + FileMode.Open, + FileAccess.Read, + FileShare.Read, + FileOptions.Asynchronous + ); + return new FileStream(handle, FileAccess.Read); +#else + // For older target frameworks, use FileStream constructor with async options + return new FileStream( + path, + FileMode.Open, + FileAccess.Read, + FileShare.Read, + bufferSize: 4096, + FileOptions.Asynchronous + ); +#endif + } + + /// + /// Opens a file stream for asynchronous reading from a FileInfo. + /// Uses File.OpenHandle with FileOptions.Asynchronous on .NET 8.0+ for optimal performance. + /// Falls back to FileStream constructor with async options on legacy frameworks. + /// + /// The FileInfo to open. + /// Cancellation token. + /// A FileStream configured for asynchronous operations. + public static Stream OpenAsyncReadStream( + this FileInfo fileInfo, + CancellationToken cancellationToken + ) + { + fileInfo.NotNull(nameof(fileInfo)); + return OpenAsyncReadStream(fileInfo.FullName, cancellationToken); + } } diff --git a/src/SharpCompress/Writers/IWriterFactory.cs b/src/SharpCompress/Writers/IWriterFactory.cs index fc2ef301b..c9eef0054 100644 --- a/src/SharpCompress/Writers/IWriterFactory.cs +++ b/src/SharpCompress/Writers/IWriterFactory.cs @@ -1,5 +1,6 @@ using System.IO; using System.Threading; +using System.Threading.Tasks; using SharpCompress.Common.Options; using SharpCompress.Factories; @@ -9,7 +10,7 @@ public interface IWriterFactory : IFactory { IWriter OpenWriter(Stream stream, IWriterOptions writerOptions); - IAsyncWriter OpenAsyncWriter( + ValueTask OpenAsyncWriter( Stream stream, IWriterOptions writerOptions, CancellationToken cancellationToken = default diff --git a/src/SharpCompress/Writers/WriterFactory.cs b/src/SharpCompress/Writers/WriterFactory.cs index 1d3927979..48ef1d474 100644 --- a/src/SharpCompress/Writers/WriterFactory.cs +++ b/src/SharpCompress/Writers/WriterFactory.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; using SharpCompress.Common; using SharpCompress.Common.Options; @@ -26,10 +27,14 @@ IWriterOptions writerOptions ) { fileInfo.NotNull(nameof(fileInfo)); - return OpenWriter(fileInfo.OpenWrite(), archiveType, writerOptions); + return OpenWriter( + fileInfo.OpenWrite(), + archiveType, + writerOptions.WithLeaveStreamOpen(false) + ); } - public static IAsyncWriter OpenAsyncWriter( + public static async ValueTask OpenAsyncWriter( string filePath, ArchiveType archiveType, IWriterOptions writerOptions, @@ -37,15 +42,16 @@ public static IAsyncWriter OpenAsyncWriter( ) { filePath.NotNullOrEmpty(nameof(filePath)); - return OpenAsyncWriter( - new FileInfo(filePath), - archiveType, - writerOptions, - cancellationToken - ); + return await OpenAsyncWriter( + new FileInfo(filePath), + archiveType, + writerOptions, + cancellationToken + ) + .ConfigureAwait(false); } - public static IAsyncWriter OpenAsyncWriter( + public static async ValueTask OpenAsyncWriter( FileInfo fileInfo, ArchiveType archiveType, IWriterOptions writerOptions, @@ -53,12 +59,14 @@ public static IAsyncWriter OpenAsyncWriter( ) { fileInfo.NotNull(nameof(fileInfo)); - return OpenAsyncWriter( - fileInfo.Open(FileMode.Create, FileAccess.Write), - archiveType, - writerOptions, - cancellationToken - ); + var stream = fileInfo.OpenAsyncWriteStream(cancellationToken); + return await OpenAsyncWriter( + stream, + archiveType, + writerOptions.WithLeaveStreamOpen(false), + cancellationToken + ) + .ConfigureAwait(false); } public static IWriter OpenWriter( @@ -86,8 +94,8 @@ IWriterOptions writerOptions /// The archive type. /// Writer options. /// Cancellation token. - /// A task that returns an IWriter. - public static IAsyncWriter OpenAsyncWriter( + /// A containing the async writer. + public static async ValueTask OpenAsyncWriter( Stream stream, ArchiveType archiveType, IWriterOptions writerOptions, @@ -100,7 +108,9 @@ public static IAsyncWriter OpenAsyncWriter( if (factory != null) { - return factory.OpenAsyncWriter(stream, writerOptions, cancellationToken); + return await factory + .OpenAsyncWriter(stream, writerOptions, cancellationToken) + .ConfigureAwait(false); } throw new NotSupportedException("Archive Type does not have a Writer: " + archiveType); diff --git a/src/SharpCompress/Writers/WriterOptionsExtensions.cs b/src/SharpCompress/Writers/WriterOptionsExtensions.cs index 9e0ce7e75..e1bdf988d 100644 --- a/src/SharpCompress/Writers/WriterOptionsExtensions.cs +++ b/src/SharpCompress/Writers/WriterOptionsExtensions.cs @@ -3,6 +3,9 @@ using SharpCompress.Common.Options; using SharpCompress.Compressors; using SharpCompress.Providers; +using SharpCompress.Writers.GZip; +using SharpCompress.Writers.Tar; +using SharpCompress.Writers.Zip; namespace SharpCompress.Writers; @@ -22,6 +25,29 @@ public static WriterOptions WithLeaveStreamOpen( bool leaveStreamOpen ) => options with { LeaveStreamOpen = leaveStreamOpen }; + /// + /// Creates a copy with the specified LeaveStreamOpen value. + /// Works with any IWriterOptions implementation. + /// + /// The source options. + /// Whether to leave the stream open. + /// A new options instance with the specified LeaveStreamOpen value. + public static IWriterOptions WithLeaveStreamOpen( + this IWriterOptions options, + bool leaveStreamOpen + ) => + options switch + { + WriterOptions writerOptions => writerOptions with { LeaveStreamOpen = leaveStreamOpen }, + ZipWriterOptions zipOptions => zipOptions with { LeaveStreamOpen = leaveStreamOpen }, + TarWriterOptions tarOptions => tarOptions with { LeaveStreamOpen = leaveStreamOpen }, + GZipWriterOptions gzipOptions => gzipOptions with { LeaveStreamOpen = leaveStreamOpen }, + _ => throw new NotSupportedException( + $"Cannot set LeaveStreamOpen on options of type {options.GetType().Name}. " + + "Options must be a record type implementing IWriterOptions." + ), + }; + /// /// Creates a copy with the specified compression level. /// diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json index 06de73fa4..5059aafeb 100644 --- a/src/SharpCompress/packages.lock.json +++ b/src/SharpCompress/packages.lock.json @@ -488,12 +488,6 @@ } }, "net9.0": { - "Microsoft.NET.ILLink.Tasks": { - "type": "Direct", - "requested": "[9.0.11, )", - "resolved": "9.0.11", - "contentHash": "vvB9rtDmWaXgYkViT00KORBVmA3pcYsHlgd9vOPqL9sf5bKy3rvLMF1+sI1uUfVj28S3itirHlHmX5/kcpZKNw==" - }, "Microsoft.NETFramework.ReferenceAssemblies": { "type": "Direct", "requested": "[1.0.3, )", diff --git a/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs b/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs index 558a989dd..67abff6ab 100644 --- a/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs +++ b/tests/SharpCompress.Performance/Benchmarks/TarBenchmarks.cs @@ -147,7 +147,7 @@ public void TarCreateSmallFiles() public async Task TarCreateSmallFilesAsync() { using var outputStream = new MemoryStream(); - await using var writer = WriterFactory.OpenAsyncWriter( + await using var writer = await WriterFactory.OpenAsyncWriter( outputStream, ArchiveType.Tar, new WriterOptions(CompressionType.None) { LeaveStreamOpen = true } diff --git a/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs b/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs index f9c53c27b..bd8188532 100644 --- a/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs +++ b/tests/SharpCompress.Performance/Benchmarks/ZipBenchmarks.cs @@ -137,7 +137,7 @@ public void ZipCreateSmallFiles() public async Task ZipCreateSmallFilesAsync() { using var outputStream = new MemoryStream(); - await using var writer = WriterFactory.OpenAsyncWriter( + await using var writer = await WriterFactory.OpenAsyncWriter( outputStream, ArchiveType.Zip, new WriterOptions(CompressionType.Deflate) { LeaveStreamOpen = true } diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index 0d98e8051..270900b9f 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -383,7 +383,7 @@ protected static IWriter CreateWriterWithLevel( return WriterFactory.OpenWriter(stream, ArchiveType.Zip, writerOptions); } - protected static IAsyncWriter CreateWriterWithLevelAsync( + protected static async ValueTask CreateWriterWithLevelAsync( Stream stream, CompressionType compressionType, int? compressionLevel = null @@ -392,7 +392,7 @@ protected static IAsyncWriter CreateWriterWithLevelAsync( var writerOptions = compressionLevel.HasValue ? new WriterOptions(compressionType, compressionLevel.Value) { LeaveStreamOpen = true } : new WriterOptions(compressionType) { LeaveStreamOpen = true }; - return WriterFactory.OpenAsyncWriter( + return await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(stream), ArchiveType.Zip, writerOptions diff --git a/tests/SharpCompress.Test/GZip/AsyncTests.cs b/tests/SharpCompress.Test/GZip/AsyncTests.cs index 8c0d19e1f..cf334ef94 100644 --- a/tests/SharpCompress.Test/GZip/AsyncTests.cs +++ b/tests/SharpCompress.Test/GZip/AsyncTests.cs @@ -104,7 +104,7 @@ public async ValueTask Writer_Async_Write_Single_File() await using (var stream = File.Create(outputPath)) #endif using ( - var writer = WriterFactory.OpenAsyncWriter( + var writer = await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(stream), ArchiveType.Zip, new WriterOptions(CompressionType.Deflate) { LeaveStreamOpen = false } diff --git a/tests/SharpCompress.Test/GZip/GZipWriterAsyncTests.cs b/tests/SharpCompress.Test/GZip/GZipWriterAsyncTests.cs index 993e16696..86c2cf355 100644 --- a/tests/SharpCompress.Test/GZip/GZipWriterAsyncTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipWriterAsyncTests.cs @@ -23,8 +23,8 @@ public async ValueTask GZip_Writer_Generic_Async() FileAccess.Write ) ) - await using ( - var writer = WriterFactory.OpenAsyncWriter( + using ( + var writer = await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(stream), ArchiveType.GZip, new WriterOptions(CompressionType.GZip) diff --git a/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs index 2a085408d..b9b7d6eb3 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs @@ -35,7 +35,7 @@ public async ValueTask Tar_FileName_Exactly_100_Characters_Async() using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) { using ( - var writer = WriterFactory.OpenAsyncWriter( + var writer = await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(stream), ArchiveType.Tar, new WriterOptions(CompressionType.None) { LeaveStreamOpen = false } @@ -94,7 +94,7 @@ public async ValueTask Tar_VeryLongFilepathReadback_Async() // Step 1: create a tar file containing a file with a long name using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) using ( - var writer = WriterFactory.OpenAsyncWriter( + var writer = await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(stream), ArchiveType.Tar, new WriterOptions(CompressionType.None) { LeaveStreamOpen = false } diff --git a/tests/SharpCompress.Test/WriterTests.cs b/tests/SharpCompress.Test/WriterTests.cs index 2e4417359..8ceefa9b0 100644 --- a/tests/SharpCompress.Test/WriterTests.cs +++ b/tests/SharpCompress.Test/WriterTests.cs @@ -70,7 +70,7 @@ protected async Task WriteAsync( writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; - using var writer = WriterFactory.OpenAsyncWriter( + await using var writer = await WriterFactory.OpenAsyncWriter( stream, _type, writerOptions, diff --git a/tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs b/tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs index 7228a2004..c65982811 100644 --- a/tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs @@ -61,7 +61,11 @@ float expectedRatio // Create zip archive in memory using var zipStream = new MemoryStream(); using ( - var writer = CreateWriterWithLevelAsync(zipStream, compressionType, compressionLevel) + var writer = await CreateWriterWithLevelAsync( + zipStream, + compressionType, + compressionLevel + ) ) { await writer.WriteAsync($"file1_{sizeMb}MiB.txt", new MemoryStream(file1Data)); @@ -131,7 +135,7 @@ float expectedRatio }; using ( - var writer = WriterFactory.OpenAsyncWriter( + var writer = await WriterFactory.OpenAsyncWriter( new AsyncOnlyStream(zipStream), ArchiveType.Zip, writerOptions @@ -198,7 +202,11 @@ float expectedRatio // Create archive with specified compression and level using var zipStream = new MemoryStream(); using ( - var writer = CreateWriterWithLevelAsync(zipStream, compressionType, compressionLevel) + var writer = await CreateWriterWithLevelAsync( + zipStream, + compressionType, + compressionLevel + ) ) { await writer.WriteAsync(