From 3aca691ea0216796992176334e12e3b2d6b4bd9a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 10 Feb 2026 12:01:16 +0000 Subject: [PATCH] first round of configure await false --- .../Archives/AbstractArchive.Async.cs | 22 ++-- .../Archives/AbstractWritableArchive.Async.cs | 4 +- .../Archives/AbstractWritableArchive.cs | 6 +- .../Archives/ArchiveFactory.Async.cs | 26 ++-- .../Archives/GZip/GZipArchive.Async.cs | 14 ++- .../Archives/IArchiveEntryExtensions.cs | 10 +- .../Archives/IAsyncArchiveExtensions.cs | 23 ++-- .../Archives/Rar/RarArchive.Async.cs | 13 +- .../Archives/Rar/RarArchive.Extensions.cs | 8 +- .../SevenZip/SevenZipArchive.Async.cs | 19 ++- .../Archives/SevenZip/SevenZipArchiveEntry.cs | 5 +- .../Archives/Tar/TarArchive.Async.cs | 4 +- .../Archives/Tar/TarArchive.Factory.cs | 2 +- .../Archives/Zip/ZipArchive.Async.cs | 2 +- .../Archives/Zip/ZipArchive.Factory.cs | 4 +- .../Archives/Zip/ZipArchiveEntry.Async.cs | 4 +- .../Common/GZip/GZipFilePart.Async.cs | 21 ++-- .../Common/Rar/Rar5CryptoInfo.cs | 43 +++---- .../Common/Tar/Headers/TarHeader.Async.cs | 14 ++- .../Zip/Headers/DirectoryEndHeader.Async.cs | 16 +-- .../Zip/Headers/DirectoryEntryHeader.Async.cs | 43 ++++--- .../Zip/Headers/LocalEntryHeader.Async.cs | 29 +++-- .../Headers/Zip64DirectoryEndHeader.Async.cs | 21 ++-- .../Zip/SeekableZipHeaderFactory.Async.cs | 25 ++-- .../Common/Zip/ZipFilePart.Async.cs | 112 ++++++++++-------- .../Compressors/LZMA/LzmaDecoder.Async.cs | 52 ++++---- src/SharpCompress/Factories/TarFactory.cs | 38 ++++-- src/SharpCompress/Factories/ZipFactory.cs | 12 +- .../LazyAsyncReadOnlyCollection.cs | 4 +- .../Readers/AbstractReader.Async.cs | 12 +- 30 files changed, 356 insertions(+), 252 deletions(-) diff --git a/src/SharpCompress/Archives/AbstractArchive.Async.cs b/src/SharpCompress/Archives/AbstractArchive.Async.cs index 9ba878d6..3f66a004 100644 --- a/src/SharpCompress/Archives/AbstractArchive.Async.cs +++ b/src/SharpCompress/Archives/AbstractArchive.Async.cs @@ -21,7 +21,7 @@ public abstract partial class AbstractArchive IAsyncEnumerable volumes ) { - foreach (var item in LoadEntries(await volumes.ToListAsync())) + foreach (var item in LoadEntries(await volumes.ToListAsync().ConfigureAwait(false))) { yield return item; } @@ -47,8 +47,8 @@ public abstract partial class AbstractArchive private async ValueTask EnsureEntriesLoadedAsync() { - await _lazyEntriesAsync.EnsureFullyLoaded(); - await _lazyVolumesAsync.EnsureFullyLoaded(); + await _lazyEntriesAsync.EnsureFullyLoaded().ConfigureAwait(false); + await _lazyVolumesAsync.EnsureFullyLoaded().ConfigureAwait(false); } private async IAsyncEnumerable EntriesAsyncCast() @@ -73,29 +73,31 @@ public abstract partial class AbstractArchive public async ValueTask ExtractAllEntriesAsync() { - if (!await IsSolidAsync() && Type != ArchiveType.SevenZip) + if (!await IsSolidAsync().ConfigureAwait(false) && Type != ArchiveType.SevenZip) { throw new SharpCompressException( "ExtractAllEntries can only be used on solid archives or 7Zip archives (which require random access)." ); } - await EnsureEntriesLoadedAsync(); - return await CreateReaderForSolidExtractionAsync(); + await EnsureEntriesLoadedAsync().ConfigureAwait(false); + return await CreateReaderForSolidExtractionAsync().ConfigureAwait(false); } public virtual ValueTask IsSolidAsync() => new(false); public async ValueTask IsCompleteAsync() { - await EnsureEntriesLoadedAsync(); - return await EntriesAsync.AllAsync(x => x.IsComplete); + await EnsureEntriesLoadedAsync().ConfigureAwait(false); + return await EntriesAsync.AllAsync(x => x.IsComplete).ConfigureAwait(false); } public async ValueTask TotalSizeAsync() => - await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.CompressedSize); + await EntriesAsync + .AggregateAsync(0L, (total, cf) => total + cf.CompressedSize) + .ConfigureAwait(false); public async ValueTask TotalUncompressedSizeAsync() => - await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.Size); + await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.Size).ConfigureAwait(false); public ValueTask IsEncryptedAsync() => new(IsEncrypted); diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs b/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs index f48b5344..4b888b7c 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs @@ -39,7 +39,7 @@ public abstract partial class AbstractWritableArchive if (!removedEntries.Contains(entry)) { removedEntries.Add(entry); - await RebuildModifiedCollectionAsync(); + await RebuildModifiedCollectionAsync().ConfigureAwait(false); } } @@ -86,7 +86,7 @@ public abstract partial class AbstractWritableArchive } var entry = CreateEntry(key, source, size, modified, closeStream); newEntries.Add(entry); - await RebuildModifiedCollectionAsync(); + await RebuildModifiedCollectionAsync().ConfigureAwait(false); return entry; } diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.cs b/src/SharpCompress/Archives/AbstractWritableArchive.cs index 5a32ef0e..59d55771 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs @@ -152,13 +152,15 @@ public abstract partial class AbstractWritableArchive long size, DateTime? modified, CancellationToken cancellationToken - ) => await AddEntryAsync(key, source, closeStream, size, modified, cancellationToken); + ) => + await AddEntryAsync(key, source, closeStream, size, modified, cancellationToken) + .ConfigureAwait(false); async ValueTask IWritableAsyncArchive.AddDirectoryEntryAsync( string key, DateTime? modified, CancellationToken cancellationToken - ) => await AddDirectoryEntryAsync(key, modified, cancellationToken); + ) => await AddDirectoryEntryAsync(key, modified, cancellationToken).ConfigureAwait(false); public TEntry AddDirectoryEntry(string key, DateTime? modified = null) { diff --git a/src/SharpCompress/Archives/ArchiveFactory.Async.cs b/src/SharpCompress/Archives/ArchiveFactory.Async.cs index c6a69d11..1ff450c1 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.Async.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.Async.cs @@ -20,7 +20,8 @@ public static partial class ArchiveFactory ) { readerOptions ??= ReaderOptions.ForExternalStream; - var factory = await FindFactoryAsync(stream, cancellationToken); + var factory = await FindFactoryAsync(stream, cancellationToken) + .ConfigureAwait(false); return factory.OpenAsyncArchive(stream, readerOptions); } @@ -42,7 +43,8 @@ public static partial class ArchiveFactory { options ??= ReaderOptions.ForOwnedFile; - var factory = await FindFactoryAsync(fileInfo, cancellationToken); + var factory = await FindFactoryAsync(fileInfo, cancellationToken) + .ConfigureAwait(false); return factory.OpenAsyncArchive(fileInfo, options); } @@ -62,13 +64,15 @@ public static partial class ArchiveFactory var fileInfo = filesArray[0]; if (filesArray.Length == 1) { - return await OpenAsyncArchive(fileInfo, options, cancellationToken); + return await OpenAsyncArchive(fileInfo, options, cancellationToken) + .ConfigureAwait(false); } fileInfo.NotNull(nameof(fileInfo)); options ??= ReaderOptions.ForOwnedFile; - var factory = await FindFactoryAsync(fileInfo, cancellationToken); + var factory = await FindFactoryAsync(fileInfo, cancellationToken) + .ConfigureAwait(false); return factory.OpenAsyncArchive(filesArray, options, cancellationToken); } @@ -89,13 +93,15 @@ public static partial class ArchiveFactory var firstStream = streamsArray[0]; if (streamsArray.Length == 1) { - return await OpenAsyncArchive(firstStream, options, cancellationToken); + return await OpenAsyncArchive(firstStream, options, cancellationToken) + .ConfigureAwait(false); } firstStream.NotNull(nameof(firstStream)); options ??= ReaderOptions.ForExternalStream; - var factory = await FindFactoryAsync(firstStream, cancellationToken); + var factory = await FindFactoryAsync(firstStream, cancellationToken) + .ConfigureAwait(false); return factory.OpenAsyncArchive(streamsArray, options); } @@ -117,7 +123,7 @@ public static partial class ArchiveFactory { finfo.NotNull(nameof(finfo)); using Stream stream = finfo.OpenRead(); - return await FindFactoryAsync(stream, cancellationToken); + return await FindFactoryAsync(stream, cancellationToken).ConfigureAwait(false); } private static async ValueTask FindFactoryAsync( @@ -140,7 +146,11 @@ public static partial class ArchiveFactory { stream.Seek(startPosition, SeekOrigin.Begin); - if (await factory.IsArchiveAsync(stream, cancellationToken: cancellationToken)) + if ( + await factory + .IsArchiveAsync(stream, cancellationToken: cancellationToken) + .ConfigureAwait(false) + ) { stream.Seek(startPosition, SeekOrigin.Begin); diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs b/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs index 82b468d8..afc64bfa 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs @@ -50,7 +50,9 @@ public partial class GZipArchive { if (!entry.IsDirectory) { - using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken); + using var entryStream = await entry + .OpenEntryStreamAsync(cancellationToken) + .ConfigureAwait(false); await writer .WriteAsync( entry.Key.NotNull("Entry Key is null"), @@ -62,7 +64,9 @@ public partial class GZipArchive } foreach (var entry in newEntries.Where(x => !x.IsDirectory)) { - using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken); + using var entryStream = await entry + .OpenEntryStreamAsync(cancellationToken) + .ConfigureAwait(false); await writer .WriteAsync(entry.Key.NotNull("Entry Key is null"), entryStream, cancellationToken) .ConfigureAwait(false); @@ -80,10 +84,12 @@ public partial class GZipArchive IAsyncEnumerable volumes ) { - var stream = (await volumes.SingleAsync()).Stream; + var stream = (await volumes.SingleAsync().ConfigureAwait(false)).Stream; yield return new GZipArchiveEntry( this, - await GZipFilePart.CreateAsync(stream, ReaderOptions.ArchiveEncoding), + await GZipFilePart + .CreateAsync(stream, ReaderOptions.ArchiveEncoding) + .ConfigureAwait(false), ReaderOptions ); } diff --git a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs index 3a5bc561..28ef61c7 100644 --- a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs @@ -47,11 +47,13 @@ public static class IArchiveEntryExtensions } #if LEGACY_DOTNET - using var entryStream = await archiveEntry.OpenEntryStreamAsync(cancellationToken); + using var entryStream = await archiveEntry + .OpenEntryStreamAsync(cancellationToken) + .ConfigureAwait(false); #else - await using var entryStream = await archiveEntry.OpenEntryStreamAsync( - cancellationToken - ); + await using var entryStream = await archiveEntry + .OpenEntryStreamAsync(cancellationToken) + .ConfigureAwait(false); #endif var sourceStream = WrapWithProgress(entryStream, archiveEntry, progress); await sourceStream diff --git a/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs b/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs index dece366d..bb00afcf 100644 --- a/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs @@ -25,20 +25,27 @@ public static class IAsyncArchiveExtensions CancellationToken cancellationToken = default ) { - if (await archive.IsSolidAsync() || archive.Type == ArchiveType.SevenZip) + if ( + await archive.IsSolidAsync().ConfigureAwait(false) + || archive.Type == ArchiveType.SevenZip + ) { - await using var reader = await archive.ExtractAllEntriesAsync(); + await using var reader = await archive + .ExtractAllEntriesAsync() + .ConfigureAwait(false); await reader .WriteAllToDirectoryAsync(destinationDirectory, cancellationToken) .ConfigureAwait(false); } else { - await archive.WriteToDirectoryAsyncInternal( - destinationDirectory, - progress, - cancellationToken - ); + await archive + .WriteToDirectoryAsyncInternal( + destinationDirectory, + progress, + cancellationToken + ) + .ConfigureAwait(false); } } @@ -48,7 +55,7 @@ public static class IAsyncArchiveExtensions CancellationToken cancellationToken ) { - var totalBytes = await archive.TotalUncompressedSizeAsync(); + var totalBytes = await archive.TotalUncompressedSizeAsync().ConfigureAwait(false); var bytesRead = 0L; var seenDirectories = new HashSet(); diff --git a/src/SharpCompress/Archives/Rar/RarArchive.Async.cs b/src/SharpCompress/Archives/Rar/RarArchive.Async.cs index 563d6bcb..ce74a3c3 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.Async.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.Async.cs @@ -25,13 +25,13 @@ public partial class RarArchive } _disposed = true; - await base.DisposeAsync(); + await base.DisposeAsync().ConfigureAwait(false); } } protected override async ValueTask CreateReaderForSolidExtractionAsync() { - if (await this.IsMultipartVolumeAsync()) + if (await this.IsMultipartVolumeAsync().ConfigureAwait(false)) { var streams = await VolumesAsync .Select(volume => @@ -39,15 +39,18 @@ public partial class RarArchive volume.Stream.Position = 0; return volume.Stream; }) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); return (RarReader)RarReader.OpenReader(streams, ReaderOptions); } - var stream = (await VolumesAsync.FirstAsync()).Stream; + var stream = (await VolumesAsync.FirstAsync().ConfigureAwait(false)).Stream; stream.Position = 0; return (RarReader)RarReader.OpenReader(stream, ReaderOptions); } public override async ValueTask IsSolidAsync() => - await (await VolumesAsync.CastAsync().FirstAsync()).IsSolidArchiveAsync(); + await (await VolumesAsync.CastAsync().FirstAsync().ConfigureAwait(false)) + .IsSolidArchiveAsync() + .ConfigureAwait(false); } diff --git a/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs b/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs index eb7c1f3b..aaca25d1 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs @@ -25,12 +25,16 @@ public static class RarArchiveExtensions /// RarArchive is the first volume of a multi-part archive. If MultipartVolume is true and IsFirstVolume is false then the first volume file must be missing. /// public async ValueTask IsFirstVolumeAsync() => - (await archive.VolumesAsync.CastAsync().FirstAsync()).IsFirstVolume; + ( + await archive.VolumesAsync.CastAsync().FirstAsync().ConfigureAwait(false) + ).IsFirstVolume; /// /// RarArchive is part of a multi-part archive. /// public async ValueTask IsMultipartVolumeAsync() => - (await archive.VolumesAsync.CastAsync().FirstAsync()).IsMultiVolume; + ( + await archive.VolumesAsync.CastAsync().FirstAsync().ConfigureAwait(false) + ).IsMultiVolume; } } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs index fb430ece..1f44fa2e 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs @@ -21,15 +21,12 @@ public partial class SevenZipArchive { stream.Position = 0; var reader = new ArchiveReader(); - await reader.OpenAsync( - stream, - lookForHeader: ReaderOptions.LookForHeader, - cancellationToken - ); - _database = await reader.ReadDatabaseAsync( - new PasswordProvider(ReaderOptions.Password), - cancellationToken - ); + await reader + .OpenAsync(stream, lookForHeader: ReaderOptions.LookForHeader, cancellationToken) + .ConfigureAwait(false); + _database = await reader + .ReadDatabaseAsync(new PasswordProvider(ReaderOptions.Password), cancellationToken) + .ConfigureAwait(false); } } @@ -37,8 +34,8 @@ public partial class SevenZipArchive IAsyncEnumerable volumes ) { - var stream = (await volumes.SingleAsync()).Stream; - await LoadFactoryAsync(stream); + var stream = (await volumes.SingleAsync().ConfigureAwait(false)).Stream; + await LoadFactoryAsync(stream).ConfigureAwait(false); if (_database is null) { yield break; diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs index 9d81d04f..36e3542d 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs @@ -19,7 +19,10 @@ public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry public async ValueTask OpenEntryStreamAsync( CancellationToken cancellationToken = default - ) => (await FilePart.GetCompressedStreamAsync(cancellationToken)).NotNull(); + ) => + ( + await FilePart.GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false) + ).NotNull(); public IArchive Archive { get; } diff --git a/src/SharpCompress/Archives/Tar/TarArchive.Async.cs b/src/SharpCompress/Archives/Tar/TarArchive.Async.cs index 24a548a8..1cd7dd91 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.Async.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.Async.cs @@ -96,7 +96,7 @@ public partial class TarArchive IAsyncEnumerable volumes ) { - var stream = (await volumes.SingleAsync()).Stream; + var stream = (await volumes.SingleAsync().ConfigureAwait(false)).Stream; if (stream.CanSeek) { stream.Position = 0; @@ -136,7 +136,7 @@ public partial class TarArchive using (var entryStream = entry.OpenEntryStream()) { using var memoryStream = new MemoryStream(); - await entryStream.CopyToAsync(memoryStream); + await entryStream.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Position = 0; var bytes = memoryStream.ToArray(); diff --git a/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs b/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs index f3faac49..5a8e83b1 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs @@ -192,7 +192,7 @@ public partial class TarArchive #else using var reader = new AsyncBinaryReader(stream, leaveOpen: true); #endif - var readSucceeded = await tarHeader.ReadAsync(reader); + var readSucceeded = await tarHeader.ReadAsync(reader).ConfigureAwait(false); var isEmptyArchive = tarHeader.Name?.Length == 0 && tarHeader.Size == 0 diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs index 431a4afd..c8139b06 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs @@ -21,7 +21,7 @@ public partial class ZipArchive IAsyncEnumerable volumes ) { - var vols = await volumes.ToListAsync(); + var vols = await volumes.ToListAsync().ConfigureAwait(false); var volsArray = vols.ToArray(); await foreach ( diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs b/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs index 56f383cc..1ad3cc33 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs @@ -228,7 +228,8 @@ public partial class ZipArchive var header = await headerFactory .ReadStreamHeaderAsync(stream) .Where(x => x.ZipHeaderType != ZipHeaderType.Split) - .FirstOrDefaultAsync(cancellationToken); + .FirstOrDefaultAsync(cancellationToken) + .ConfigureAwait(false); if (header is null) { return false; @@ -271,6 +272,7 @@ public partial class ZipArchive await foreach ( var h in z.ReadSeekableHeaderAsync(stream) .WithCancellation(cancellationToken) + .ConfigureAwait(false) ) { x = h; diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs index 2d76dcd7..308727a6 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs @@ -15,7 +15,9 @@ public partial class ZipArchiveEntry var part = Parts.Single(); if (part is SeekableZipFilePart seekablePart) { - return (await seekablePart.GetCompressedStreamAsync(cancellationToken)).NotNull(); + return ( + await seekablePart.GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false) + ).NotNull(); } return OpenEntryStream(); } diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs b/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs index 34c3c697..1d56c7bd 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs @@ -19,12 +19,12 @@ internal sealed partial class GZipFilePart { var part = new GZipFilePart(stream, archiveEncoding); - await part.ReadAndValidateGzipHeaderAsync(cancellationToken); + await part.ReadAndValidateGzipHeaderAsync(cancellationToken).ConfigureAwait(false); if (stream.CanSeek) { var position = stream.Position; stream.Position = stream.Length - 8; - await part.ReadTrailerAsync(cancellationToken); + await part.ReadTrailerAsync(cancellationToken).ConfigureAwait(false); stream.Position = position; part.EntryStartPosition = position; } @@ -41,7 +41,7 @@ internal sealed partial class GZipFilePart { // Read and potentially verify the GZIP trailer: CRC32 and size mod 2^32 var trailer = new byte[8]; - _ = await _stream.ReadFullyAsync(trailer, 0, 8, cancellationToken); + _ = await _stream.ReadFullyAsync(trailer, 0, 8, cancellationToken).ConfigureAwait(false); Crc = BinaryPrimitives.ReadUInt32LittleEndian(trailer); UncompressedSize = BinaryPrimitives.ReadUInt32LittleEndian(trailer.AsSpan().Slice(4)); @@ -53,7 +53,7 @@ internal sealed partial class GZipFilePart { // read the header on the first read var header = new byte[10]; - var n = await _stream.ReadAsync(header, 0, 10, cancellationToken); + var n = await _stream.ReadAsync(header, 0, 10, cancellationToken).ConfigureAwait(false); // workitem 8501: handle edge case (decompress empty stream) if (n == 0) @@ -77,28 +77,29 @@ internal sealed partial class GZipFilePart { // read and discard extra field var lengthField = new byte[2]; - _ = await _stream.ReadAsync(lengthField, 0, 2, cancellationToken); + _ = await _stream.ReadAsync(lengthField, 0, 2, cancellationToken).ConfigureAwait(false); var extraLength = (short)(lengthField[0] + (lengthField[1] * 256)); var extra = new byte[extraLength]; - if (!await _stream.ReadFullyAsync(extra, cancellationToken)) + if (!await _stream.ReadFullyAsync(extra, cancellationToken).ConfigureAwait(false)) { throw new ZlibException("Unexpected end-of-file reading GZIP header."); } } if ((header[3] & 0x08) == 0x08) { - _name = await ReadZeroTerminatedStringAsync(_stream, cancellationToken); + _name = await ReadZeroTerminatedStringAsync(_stream, cancellationToken) + .ConfigureAwait(false); } if ((header[3] & 0x10) == 0x010) { - await ReadZeroTerminatedStringAsync(_stream, cancellationToken); + await ReadZeroTerminatedStringAsync(_stream, cancellationToken).ConfigureAwait(false); } if ((header[3] & 0x02) == 0x02) { var buf = new byte[1]; - _ = await _stream.ReadAsync(buf, 0, 1, cancellationToken); // CRC16, ignore + _ = await _stream.ReadAsync(buf, 0, 1, cancellationToken).ConfigureAwait(false); // CRC16, ignore } } @@ -113,7 +114,7 @@ internal sealed partial class GZipFilePart do { // workitem 7740 - var n = await stream.ReadAsync(buf1, 0, 1, cancellationToken); + var n = await stream.ReadAsync(buf1, 0, 1, cancellationToken).ConfigureAwait(false); if (n != 1) { throw new ZlibException("Unexpected EOF reading GZIP header."); diff --git a/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs b/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs index c02ac5c9..f86e4a38 100644 --- a/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs +++ b/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs @@ -57,47 +57,46 @@ internal class Rar5CryptoInfo ) { var cryptoInfo = new Rar5CryptoInfo(); - var cryptVersion = await reader.ReadRarVIntUInt32Async( - cancellationToken: CancellationToken.None - ); + var cryptVersion = await reader + .ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None) + .ConfigureAwait(false); if (cryptVersion > EncryptionConstV5.VERSION) { throw new CryptographicException($"Unsupported crypto version of {cryptVersion}"); } - var encryptionFlags = await reader.ReadRarVIntUInt32Async( - cancellationToken: CancellationToken.None - ); + var encryptionFlags = await reader + .ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None) + .ConfigureAwait(false); cryptoInfo.UsePswCheck = FlagUtility.HasFlag( encryptionFlags, EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK ); cryptoInfo.LG2Count = (int) - await reader.ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None); + await reader + .ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None) + .ConfigureAwait(false); if (cryptoInfo.LG2Count > EncryptionConstV5.CRYPT5_KDF_LG2_COUNT_MAX) { throw new CryptographicException($"Unsupported LG2 count of {cryptoInfo.LG2Count}."); } - cryptoInfo.Salt = await reader.ReadBytesAsync( - EncryptionConstV5.SIZE_SALT50, - CancellationToken.None - ); + cryptoInfo.Salt = await reader + .ReadBytesAsync(EncryptionConstV5.SIZE_SALT50, CancellationToken.None) + .ConfigureAwait(false); if (readInitV) { - await cryptoInfo.ReadInitVAsync(reader); + await cryptoInfo.ReadInitVAsync(reader).ConfigureAwait(false); } if (cryptoInfo.UsePswCheck) { - cryptoInfo.PswCheck = await reader.ReadBytesAsync( - EncryptionConstV5.SIZE_PSWCHECK, - CancellationToken.None - ); - var _pswCheckCsm = await reader.ReadBytesAsync( - EncryptionConstV5.SIZE_PSWCHECK_CSUM, - CancellationToken.None - ); + cryptoInfo.PswCheck = await reader + .ReadBytesAsync(EncryptionConstV5.SIZE_PSWCHECK, CancellationToken.None) + .ConfigureAwait(false); + var _pswCheckCsm = await reader + .ReadBytesAsync(EncryptionConstV5.SIZE_PSWCHECK_CSUM, CancellationToken.None) + .ConfigureAwait(false); var sha = SHA256.Create(); cryptoInfo.UsePswCheck = sha.ComputeHash(cryptoInfo.PswCheck) @@ -111,7 +110,9 @@ internal class Rar5CryptoInfo InitV = reader.ReadBytes(EncryptionConstV5.SIZE_INITV); public async ValueTask ReadInitVAsync(AsyncMarkingBinaryReader reader) => - InitV = await reader.ReadBytesAsync(EncryptionConstV5.SIZE_INITV, CancellationToken.None); + InitV = await reader + .ReadBytesAsync(EncryptionConstV5.SIZE_INITV, CancellationToken.None) + .ConfigureAwait(false); public bool UsePswCheck = false; diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs index f5d796a4..8f1bd75f 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs @@ -203,7 +203,7 @@ internal sealed partial class TarHeader do { - buffer = await ReadBlockAsync(reader); + buffer = await ReadBlockAsync(reader).ConfigureAwait(false); if (buffer.Length == 0) { @@ -216,12 +216,12 @@ internal sealed partial class TarHeader // to apply to the header that follows them. if (entryType == EntryType.LongName) { - longName = await ReadLongNameAsync(reader, buffer); + longName = await ReadLongNameAsync(reader, buffer).ConfigureAwait(false); continue; } else if (entryType == EntryType.LongLink) { - longLinkName = await ReadLongNameAsync(reader, buffer); + longLinkName = await ReadLongNameAsync(reader, buffer).ConfigureAwait(false); continue; } @@ -282,7 +282,7 @@ internal sealed partial class TarHeader var buffer = ArrayPool.Shared.Rent(BLOCK_SIZE); try { - await reader.ReadBytesAsync(buffer, 0, BLOCK_SIZE); + await reader.ReadBytesAsync(buffer, 0, BLOCK_SIZE).ConfigureAwait(false); if (buffer.Length != 0 && buffer.Length < BLOCK_SIZE) { @@ -313,7 +313,7 @@ internal sealed partial class TarHeader var nameBytes = ArrayPool.Shared.Rent(nameLength); try { - await reader.ReadBytesAsync(nameBytes, 0, nameLength); + await reader.ReadBytesAsync(nameBytes, 0, nameLength).ConfigureAwait(false); var remainingBytesToRead = BLOCK_SIZE - (nameLength % BLOCK_SIZE); // Read the rest of the block and discard the data @@ -322,7 +322,9 @@ internal sealed partial class TarHeader var remainingBytes = ArrayPool.Shared.Rent(remainingBytesToRead); try { - await reader.ReadBytesAsync(remainingBytes, 0, remainingBytesToRead); + await reader + .ReadBytesAsync(remainingBytes, 0, remainingBytesToRead) + .ConfigureAwait(false); } finally { diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs index 86e0f771..40b4ffc7 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs @@ -8,14 +8,14 @@ internal partial class DirectoryEndHeader { internal override async ValueTask Read(AsyncBinaryReader reader) { - VolumeNumber = await reader.ReadUInt16Async(); - FirstVolumeWithDirectory = await reader.ReadUInt16Async(); - TotalNumberOfEntriesInDisk = await reader.ReadUInt16Async(); - TotalNumberOfEntries = await reader.ReadUInt16Async(); - DirectorySize = await reader.ReadUInt32Async(); - DirectoryStartOffsetRelativeToDisk = await reader.ReadUInt32Async(); - CommentLength = await reader.ReadUInt16Async(); + VolumeNumber = await reader.ReadUInt16Async().ConfigureAwait(false); + FirstVolumeWithDirectory = await reader.ReadUInt16Async().ConfigureAwait(false); + TotalNumberOfEntriesInDisk = await reader.ReadUInt16Async().ConfigureAwait(false); + TotalNumberOfEntries = await reader.ReadUInt16Async().ConfigureAwait(false); + DirectorySize = await reader.ReadUInt32Async().ConfigureAwait(false); + DirectoryStartOffsetRelativeToDisk = await reader.ReadUInt32Async().ConfigureAwait(false); + CommentLength = await reader.ReadUInt16Async().ConfigureAwait(false); Comment = new byte[CommentLength]; - await reader.ReadBytesAsync(Comment, 0, CommentLength); + await reader.ReadBytesAsync(Comment, 0, CommentLength).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.Async.cs index 6cc356d6..c09cac91 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.Async.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.Async.cs @@ -10,28 +10,33 @@ internal partial class DirectoryEntryHeader { internal override async ValueTask Read(AsyncBinaryReader reader) { - Version = await reader.ReadUInt16Async(); - VersionNeededToExtract = await reader.ReadUInt16Async(); - Flags = (HeaderFlags)await reader.ReadUInt16Async(); - CompressionMethod = (ZipCompressionMethod)await reader.ReadUInt16Async(); - OriginalLastModifiedTime = LastModifiedTime = await reader.ReadUInt16Async(); - OriginalLastModifiedDate = LastModifiedDate = await reader.ReadUInt16Async(); - Crc = await reader.ReadUInt32Async(); - CompressedSize = await reader.ReadUInt32Async(); - UncompressedSize = await reader.ReadUInt32Async(); - var nameLength = await reader.ReadUInt16Async(); - var extraLength = await reader.ReadUInt16Async(); - var commentLength = await reader.ReadUInt16Async(); - DiskNumberStart = await reader.ReadUInt16Async(); - InternalFileAttributes = await reader.ReadUInt16Async(); - ExternalFileAttributes = await reader.ReadUInt32Async(); - RelativeOffsetOfEntryHeader = await reader.ReadUInt32Async(); + Version = await reader.ReadUInt16Async().ConfigureAwait(false); + VersionNeededToExtract = await reader.ReadUInt16Async().ConfigureAwait(false); + Flags = (HeaderFlags)await reader.ReadUInt16Async().ConfigureAwait(false); + CompressionMethod = (ZipCompressionMethod) + await reader.ReadUInt16Async().ConfigureAwait(false); + OriginalLastModifiedTime = LastModifiedTime = await reader + .ReadUInt16Async() + .ConfigureAwait(false); + OriginalLastModifiedDate = LastModifiedDate = await reader + .ReadUInt16Async() + .ConfigureAwait(false); + Crc = await reader.ReadUInt32Async().ConfigureAwait(false); + CompressedSize = await reader.ReadUInt32Async().ConfigureAwait(false); + UncompressedSize = await reader.ReadUInt32Async().ConfigureAwait(false); + var nameLength = await reader.ReadUInt16Async().ConfigureAwait(false); + var extraLength = await reader.ReadUInt16Async().ConfigureAwait(false); + var commentLength = await reader.ReadUInt16Async().ConfigureAwait(false); + DiskNumberStart = await reader.ReadUInt16Async().ConfigureAwait(false); + InternalFileAttributes = await reader.ReadUInt16Async().ConfigureAwait(false); + ExternalFileAttributes = await reader.ReadUInt32Async().ConfigureAwait(false); + RelativeOffsetOfEntryHeader = await reader.ReadUInt32Async().ConfigureAwait(false); var name = new byte[nameLength]; var extra = new byte[extraLength]; var comment = new byte[commentLength]; - await reader.ReadBytesAsync(name, 0, nameLength); - await reader.ReadBytesAsync(extra, 0, extraLength); - await reader.ReadBytesAsync(comment, 0, commentLength); + await reader.ReadBytesAsync(name, 0, nameLength).ConfigureAwait(false); + await reader.ReadBytesAsync(extra, 0, extraLength).ConfigureAwait(false); + await reader.ReadBytesAsync(comment, 0, commentLength).ConfigureAwait(false); ProcessReadData(name, extra, comment); } diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.Async.cs index 9a8a991e..950494df 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.Async.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.Async.cs @@ -9,20 +9,25 @@ internal partial class LocalEntryHeader { internal override async ValueTask Read(AsyncBinaryReader reader) { - Version = await reader.ReadUInt16Async(); - Flags = (HeaderFlags)await reader.ReadUInt16Async(); - CompressionMethod = (ZipCompressionMethod)await reader.ReadUInt16Async(); - OriginalLastModifiedTime = LastModifiedTime = await reader.ReadUInt16Async(); - OriginalLastModifiedDate = LastModifiedDate = await reader.ReadUInt16Async(); - Crc = await reader.ReadUInt32Async(); - CompressedSize = await reader.ReadUInt32Async(); - UncompressedSize = await reader.ReadUInt32Async(); - var nameLength = await reader.ReadUInt16Async(); - var extraLength = await reader.ReadUInt16Async(); + Version = await reader.ReadUInt16Async().ConfigureAwait(false); + Flags = (HeaderFlags)await reader.ReadUInt16Async().ConfigureAwait(false); + CompressionMethod = (ZipCompressionMethod) + await reader.ReadUInt16Async().ConfigureAwait(false); + OriginalLastModifiedTime = LastModifiedTime = await reader + .ReadUInt16Async() + .ConfigureAwait(false); + OriginalLastModifiedDate = LastModifiedDate = await reader + .ReadUInt16Async() + .ConfigureAwait(false); + Crc = await reader.ReadUInt32Async().ConfigureAwait(false); + CompressedSize = await reader.ReadUInt32Async().ConfigureAwait(false); + UncompressedSize = await reader.ReadUInt32Async().ConfigureAwait(false); + var nameLength = await reader.ReadUInt16Async().ConfigureAwait(false); + var extraLength = await reader.ReadUInt16Async().ConfigureAwait(false); var name = new byte[nameLength]; var extra = new byte[extraLength]; - await reader.ReadBytesAsync(name, 0, nameLength); - await reader.ReadBytesAsync(extra, 0, extraLength); + await reader.ReadBytesAsync(name, 0, nameLength).ConfigureAwait(false); + await reader.ReadBytesAsync(extra, 0, extraLength).ConfigureAwait(false); ProcessReadData(name, extra); } diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.Async.cs index 9bbfe4f8..9e510688 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.Async.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.Async.cs @@ -8,19 +8,20 @@ internal partial class Zip64DirectoryEndHeader { internal override async ValueTask Read(AsyncBinaryReader reader) { - SizeOfDirectoryEndRecord = (long)await reader.ReadUInt64Async(); - VersionMadeBy = await reader.ReadUInt16Async(); - VersionNeededToExtract = await reader.ReadUInt16Async(); - VolumeNumber = await reader.ReadUInt32Async(); - FirstVolumeWithDirectory = await reader.ReadUInt32Async(); - TotalNumberOfEntriesInDisk = (long)await reader.ReadUInt64Async(); - TotalNumberOfEntries = (long)await reader.ReadUInt64Async(); - DirectorySize = (long)await reader.ReadUInt64Async(); - DirectoryStartOffsetRelativeToDisk = (long)await reader.ReadUInt64Async(); + SizeOfDirectoryEndRecord = (long)await reader.ReadUInt64Async().ConfigureAwait(false); + VersionMadeBy = await reader.ReadUInt16Async().ConfigureAwait(false); + VersionNeededToExtract = await reader.ReadUInt16Async().ConfigureAwait(false); + VolumeNumber = await reader.ReadUInt32Async().ConfigureAwait(false); + FirstVolumeWithDirectory = await reader.ReadUInt32Async().ConfigureAwait(false); + TotalNumberOfEntriesInDisk = (long)await reader.ReadUInt64Async().ConfigureAwait(false); + TotalNumberOfEntries = (long)await reader.ReadUInt64Async().ConfigureAwait(false); + DirectorySize = (long)await reader.ReadUInt64Async().ConfigureAwait(false); + DirectoryStartOffsetRelativeToDisk = (long) + await reader.ReadUInt64Async().ConfigureAwait(false); var size = (int)( SizeOfDirectoryEndRecord - SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS ); DataSector = new byte[size]; - await reader.ReadBytesAsync(DataSector, 0, size); + await reader.ReadBytesAsync(DataSector, 0, size).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs index 23422ae4..d7372b00 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs @@ -18,11 +18,11 @@ internal sealed partial class SeekableZipHeaderFactory using var reader = new AsyncBinaryReader(stream, leaveOpen: true); #endif - await SeekBackToHeaderAsync(stream, reader); + await SeekBackToHeaderAsync(stream, reader).ConfigureAwait(false); var eocd_location = stream.Position; var entry = new DirectoryEndHeader(); - await entry.Read(reader); + await entry.Read(reader).ConfigureAwait(false); if (entry.IsZip64) { @@ -30,24 +30,24 @@ internal sealed partial class SeekableZipHeaderFactory // ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR should be before the EOCD stream.Seek(eocd_location - ZIP64_EOCD_LENGTH - 4, SeekOrigin.Begin); - uint zip64_locator = await reader.ReadUInt32Async(); + uint zip64_locator = await reader.ReadUInt32Async().ConfigureAwait(false); if (zip64_locator != ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR) { throw new ArchiveException("Failed to locate the Zip64 Directory Locator"); } var zip64Locator = new Zip64DirectoryEndLocatorHeader(); - await zip64Locator.Read(reader); + await zip64Locator.Read(reader).ConfigureAwait(false); stream.Seek(zip64Locator.RelativeOffsetOfTheEndOfDirectoryRecord, SeekOrigin.Begin); - var zip64Signature = await reader.ReadUInt32Async(); + var zip64Signature = await reader.ReadUInt32Async().ConfigureAwait(false); if (zip64Signature != ZIP64_END_OF_CENTRAL_DIRECTORY) { throw new ArchiveException("Failed to locate the Zip64 Header"); } var zip64Entry = new Zip64DirectoryEndHeader(); - await zip64Entry.Read(reader); + await zip64Entry.Read(reader).ConfigureAwait(false); stream.Seek(zip64Entry.DirectoryStartOffsetRelativeToDisk, SeekOrigin.Begin); } else @@ -59,8 +59,8 @@ internal sealed partial class SeekableZipHeaderFactory while (true) { stream.Position = position; - var signature = await reader.ReadUInt32Async(); - var nextHeader = await ReadHeader(signature, reader, _zip64); + var signature = await reader.ReadUInt32Async().ConfigureAwait(false); + var nextHeader = await ReadHeader(signature, reader, _zip64).ConfigureAwait(false); position = stream.Position; if (nextHeader is null) @@ -101,7 +101,7 @@ internal sealed partial class SeekableZipHeaderFactory try { - await reader.ReadBytesAsync(seek, 0, len, default); + await reader.ReadBytesAsync(seek, 0, len, default).ConfigureAwait(false); var memory = new Memory(seek, 0, len); var span = memory.Span; span.Reverse(); @@ -137,8 +137,11 @@ internal sealed partial class SeekableZipHeaderFactory #else using var reader = new AsyncBinaryReader(stream, leaveOpen: true); #endif - var signature = await reader.ReadUInt32Async(); - if (await ReadHeader(signature, reader, _zip64) is not LocalEntryHeader localEntryHeader) + var signature = await reader.ReadUInt32Async().ConfigureAwait(false); + if ( + await ReadHeader(signature, reader, _zip64).ConfigureAwait(false) + is not LocalEntryHeader localEntryHeader + ) { throw new InvalidOperationException(); } diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs b/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs index bcd5650f..818d1bdb 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs @@ -148,53 +148,63 @@ internal abstract partial class ZipFilePart } case ZipCompressionMethod.Reduce1: { - return await ReduceStream.CreateAsync( - stream, - Header.CompressedSize, - Header.UncompressedSize, - 1, - cancellationToken - ); + return await ReduceStream + .CreateAsync( + stream, + Header.CompressedSize, + Header.UncompressedSize, + 1, + cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Reduce2: { - return await ReduceStream.CreateAsync( - stream, - Header.CompressedSize, - Header.UncompressedSize, - 2, - cancellationToken - ); + return await ReduceStream + .CreateAsync( + stream, + Header.CompressedSize, + Header.UncompressedSize, + 2, + cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Reduce3: { - return await ReduceStream.CreateAsync( - stream, - Header.CompressedSize, - Header.UncompressedSize, - 3, - cancellationToken - ); + return await ReduceStream + .CreateAsync( + stream, + Header.CompressedSize, + Header.UncompressedSize, + 3, + cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Reduce4: { - return await ReduceStream.CreateAsync( - stream, - Header.CompressedSize, - Header.UncompressedSize, - 4, - cancellationToken - ); + return await ReduceStream + .CreateAsync( + stream, + Header.CompressedSize, + Header.UncompressedSize, + 4, + cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Explode: { - return await ExplodeStream.CreateAsync( - stream, - Header.CompressedSize, - Header.UncompressedSize, - Header.Flags, - cancellationToken - ); + return await ExplodeStream + .CreateAsync( + stream, + Header.CompressedSize, + Header.UncompressedSize, + Header.Flags, + cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Deflate: @@ -207,12 +217,14 @@ internal abstract partial class ZipFilePart } case ZipCompressionMethod.BZip2: { - return await BZip2Stream.CreateAsync( - stream, - CompressionMode.Decompress, - false, - cancellationToken: cancellationToken - ); + return await BZip2Stream + .CreateAsync( + stream, + CompressionMode.Decompress, + false, + cancellationToken: cancellationToken + ) + .ConfigureAwait(false); } case ZipCompressionMethod.LZMA: { @@ -228,14 +240,16 @@ internal abstract partial class ZipFilePart await stream .ReadFullyAsync(props, 0, propsSize, cancellationToken) .ConfigureAwait(false); - return await LzmaStream.CreateAsync( - props, - stream, - Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1, - FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1) - ? -1 - : Header.UncompressedSize - ); + return await LzmaStream + .CreateAsync( + props, + stream, + Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1, + FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1) + ? -1 + : Header.UncompressedSize + ) + .ConfigureAwait(false); } case ZipCompressionMethod.Xz: { diff --git a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs index add73b8e..24860c8d 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs @@ -178,29 +178,34 @@ public partial class Decoder : ICoder, ISetDecoderProperties var posState = (uint)outWindow.Total & _posStateMask; if ( await _isMatchDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { byte b; var prevByte = outWindow.GetByte(0); if (!_state.IsCharState()) { - b = await _literalDecoder.DecodeWithMatchByteAsync( - rangeDecoder, - (uint)outWindow.Total, - prevByte, - outWindow.GetByte((int)_rep0), - cancellationToken - ); + b = await _literalDecoder + .DecodeWithMatchByteAsync( + rangeDecoder, + (uint)outWindow.Total, + prevByte, + outWindow.GetByte((int)_rep0), + cancellationToken + ) + .ConfigureAwait(false); } else { - b = await _literalDecoder.DecodeNormalAsync( - rangeDecoder, - (uint)outWindow.Total, - prevByte, - cancellationToken - ); + b = await _literalDecoder + .DecodeNormalAsync( + rangeDecoder, + (uint)outWindow.Total, + prevByte, + cancellationToken + ) + .ConfigureAwait(false); } await outWindow.PutByteAsync(b, cancellationToken).ConfigureAwait(false); _state.UpdateChar(); @@ -209,20 +214,23 @@ public partial class Decoder : ICoder, ISetDecoderProperties { uint len; if ( - await _isRepDecoders[_state._index].DecodeAsync(rangeDecoder, cancellationToken) - == 1 + await _isRepDecoders[_state._index] + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 1 ) { if ( await _isRepG0Decoders[_state._index] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { if ( await _isRep0LongDecoders[ (_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState ] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { _state.UpdateShortRep(); @@ -237,7 +245,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties uint distance; if ( await _isRepG1Decoders[_state._index] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { distance = _rep1; @@ -246,7 +255,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties { if ( await _isRepG2Decoders[_state._index] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { distance = _rep2; @@ -339,6 +349,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties { CreateDictionary(); } - await _outWindow.TrainAsync(stream); + await _outWindow.TrainAsync(stream).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index f399b984..bd8b228c 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -82,14 +82,21 @@ public class TarFactory foreach (var wrapper in TarWrapper.Wrappers) { sharpCompressStream.Rewind(); - if (await wrapper.IsMatchAsync(sharpCompressStream, cancellationToken)) + if ( + await wrapper + .IsMatchAsync(sharpCompressStream, cancellationToken) + .ConfigureAwait(false) + ) { sharpCompressStream.Rewind(); - var decompressedStream = await wrapper.CreateStreamAsync( - sharpCompressStream, - cancellationToken - ); - if (await TarArchive.IsTarFileAsync(decompressedStream, cancellationToken)) + var decompressedStream = await wrapper + .CreateStreamAsync(sharpCompressStream, cancellationToken) + .ConfigureAwait(false); + if ( + await TarArchive + .IsTarFileAsync(decompressedStream, cancellationToken) + .ConfigureAwait(false) + ) { sharpCompressStream.Rewind(); return true; @@ -194,14 +201,21 @@ public class TarFactory foreach (var wrapper in TarWrapper.Wrappers) { sharpCompressStream.Rewind(); - if (await wrapper.IsMatchAsync(sharpCompressStream, cancellationToken)) + if ( + await wrapper + .IsMatchAsync(sharpCompressStream, cancellationToken) + .ConfigureAwait(false) + ) { sharpCompressStream.Rewind(); - var decompressedStream = await wrapper.CreateStreamAsync( - sharpCompressStream, - cancellationToken - ); - if (await TarArchive.IsTarFileAsync(decompressedStream, cancellationToken)) + var decompressedStream = await wrapper + .CreateStreamAsync(sharpCompressStream, cancellationToken) + .ConfigureAwait(false); + if ( + await TarArchive + .IsTarFileAsync(decompressedStream, cancellationToken) + .ConfigureAwait(false) + ) { sharpCompressStream.Rewind(); sharpCompressStream.StopRecording(); diff --git a/src/SharpCompress/Factories/ZipFactory.cs b/src/SharpCompress/Factories/ZipFactory.cs index f22cdf2e..b88ea962 100644 --- a/src/SharpCompress/Factories/ZipFactory.cs +++ b/src/SharpCompress/Factories/ZipFactory.cs @@ -82,7 +82,11 @@ public class ZipFactory var startPosition = stream.CanSeek ? stream.Position : -1; // probe for single volume zip - if (await ZipArchive.IsZipFileAsync(stream, password, cancellationToken)) + if ( + await ZipArchive + .IsZipFileAsync(stream, password, cancellationToken) + .ConfigureAwait(false) + ) { return true; } @@ -96,7 +100,11 @@ public class ZipFactory stream.Position = startPosition; //test the zip (last) file of a multipart zip - if (await ZipArchive.IsZipMultiAsync(stream, password, cancellationToken)) + if ( + await ZipArchive + .IsZipMultiAsync(stream, password, cancellationToken) + .ConfigureAwait(false) + ) { return true; } diff --git a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs index 114bc71a..6d152593 100644 --- a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs +++ b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs @@ -41,7 +41,7 @@ internal sealed class LazyAsyncReadOnlyCollection(IAsyncEnumerable source) } if ( !lazyReadOnlyCollection._fullyLoaded - && await lazyReadOnlyCollection._source.MoveNextAsync() + && await lazyReadOnlyCollection._source.MoveNextAsync().ConfigureAwait(false) ) { lazyReadOnlyCollection._backing.Add(lazyReadOnlyCollection._source.Current); @@ -76,7 +76,7 @@ internal sealed class LazyAsyncReadOnlyCollection(IAsyncEnumerable source) if (!_fullyLoaded) { var loader = new LazyLoader(this, CancellationToken.None); - while (await loader.MoveNextAsync()) + while (await loader.MoveNextAsync().ConfigureAwait(false)) { // Intentionally empty } diff --git a/src/SharpCompress/Readers/AbstractReader.Async.cs b/src/SharpCompress/Readers/AbstractReader.Async.cs index 958045e0..fa045d8a 100644 --- a/src/SharpCompress/Readers/AbstractReader.Async.cs +++ b/src/SharpCompress/Readers/AbstractReader.Async.cs @@ -17,13 +17,13 @@ public abstract partial class AbstractReader { if (_entriesForCurrentReadStreamAsync is not null) { - await _entriesForCurrentReadStreamAsync.DisposeAsync(); + await _entriesForCurrentReadStreamAsync.DisposeAsync().ConfigureAwait(false); } // If Volume implements IAsyncDisposable, use async disposal if (Volume is IAsyncDisposable asyncDisposable) { - await asyncDisposable.DisposeAsync(); + await asyncDisposable.DisposeAsync().ConfigureAwait(false); } else { @@ -43,14 +43,14 @@ public abstract partial class AbstractReader } if (_entriesForCurrentReadStreamAsync is null) { - return await LoadStreamForReadingAsync(RequestInitialStream()); + return await LoadStreamForReadingAsync(RequestInitialStream()).ConfigureAwait(false); } if (!_wroteCurrentEntry) { await SkipEntryAsync(cancellationToken).ConfigureAwait(false); } _wroteCurrentEntry = false; - if (await NextEntryForCurrentStreamAsync(cancellationToken)) + if (await NextEntryForCurrentStreamAsync(cancellationToken).ConfigureAwait(false)) { return true; } @@ -62,7 +62,7 @@ public abstract partial class AbstractReader { if (_entriesForCurrentReadStreamAsync is not null) { - await _entriesForCurrentReadStreamAsync.DisposeAsync(); + await _entriesForCurrentReadStreamAsync.DisposeAsync().ConfigureAwait(false); } if (stream is null || !stream.CanRead) { @@ -73,7 +73,7 @@ public abstract partial class AbstractReader ); } _entriesForCurrentReadStreamAsync = GetEntriesAsync(stream).GetAsyncEnumerator(); - return await _entriesForCurrentReadStreamAsync.MoveNextAsync(); + return await _entriesForCurrentReadStreamAsync.MoveNextAsync().ConfigureAwait(false); } private async ValueTask SkipEntryAsync(CancellationToken cancellationToken)