diff --git a/src/SharpCompress/Archives/AbstractArchive.Async.cs b/src/SharpCompress/Archives/AbstractArchive.Async.cs index 9ba878d68..3f66a004a 100644 --- a/src/SharpCompress/Archives/AbstractArchive.Async.cs +++ b/src/SharpCompress/Archives/AbstractArchive.Async.cs @@ -21,7 +21,7 @@ protected virtual async IAsyncEnumerable LoadEntriesAsync( 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 virtual async ValueTask DisposeAsync() 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 @@ private async IAsyncEnumerable VolumesAsyncCast() 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 f48b53440..8b8434e7b 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.Async.cs @@ -39,7 +39,7 @@ public async ValueTask RemoveEntryAsync(TEntry entry) if (!removedEntries.Contains(entry)) { removedEntries.Add(entry); - await RebuildModifiedCollectionAsync(); + await RebuildModifiedCollectionAsync().ConfigureAwait(false); } } @@ -86,7 +86,7 @@ public async ValueTask AddEntryAsync( } var entry = CreateEntry(key, source, size, modified, closeStream); newEntries.Add(entry); - await RebuildModifiedCollectionAsync(); + await RebuildModifiedCollectionAsync().ConfigureAwait(false); return entry; } @@ -106,7 +106,7 @@ public async ValueTask AddDirectoryEntryAsync( } var entry = CreateDirectoryEntry(key, modified); 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 5a32ef0ee..59d557715 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs @@ -152,13 +152,15 @@ async ValueTask IWritableAsyncArchive.AddEntryAsync( 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 b9df44dbb..8c6d9e347 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.Async.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.Async.cs @@ -20,7 +20,8 @@ public static async ValueTask OpenAsyncArchive( ) { 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 async ValueTask OpenAsyncArchive( { 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 async ValueTask OpenAsyncArchive( 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); } @@ -89,13 +93,15 @@ public static async ValueTask OpenAsyncArchive( 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 @@ CancellationToken cancellationToken { 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 @@ CancellationToken cancellationToken { 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 82b468d8d..afc64bfae 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs @@ -50,7 +50,9 @@ var entry in oldEntries.WithCancellation(cancellationToken).ConfigureAwait(false { 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 @@ await writer } 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 @@ protected override async IAsyncEnumerable LoadEntriesAsync( 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 3a5bc5612..28ef61c7c 100644 --- a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs @@ -47,11 +47,13 @@ public async ValueTask WriteToAsync( } #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 dece366d6..bb00afcf8 100644 --- a/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IAsyncArchiveExtensions.cs @@ -25,20 +25,27 @@ public async ValueTask WriteToDirectoryAsync( 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 @@ private async ValueTask WriteToDirectoryAsyncInternal( 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/IWritableAsyncArchiveExtensions.cs b/src/SharpCompress/Archives/IWritableAsyncArchiveExtensions.cs index 365cf8529..4bdc792f6 100644 --- a/src/SharpCompress/Archives/IWritableAsyncArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IWritableAsyncArchiveExtensions.cs @@ -25,13 +25,15 @@ var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption) ) { var fileInfo = new FileInfo(path); - await writableArchive.AddEntryAsync( - path.Substring(filePath.Length), - fileInfo.OpenRead(), - true, - fileInfo.Length, - fileInfo.LastWriteTime - ); + await writableArchive + .AddEntryAsync( + path.Substring(filePath.Length), + fileInfo.OpenRead(), + true, + fileInfo.Length, + fileInfo.LastWriteTime + ) + .ConfigureAwait(false); } } } diff --git a/src/SharpCompress/Archives/Rar/RarArchive.Async.cs b/src/SharpCompress/Archives/Rar/RarArchive.Async.cs index 563d6bcb7..ce74a3c32 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.Async.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.Async.cs @@ -25,13 +25,13 @@ public override async ValueTask DisposeAsync() } _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 @@ protected override async ValueTask CreateReaderForSolidExtractionA 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 eb7c1f3be..aaca25d16 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/Rar/RarArchiveEntry.Async.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.Async.cs index dbc2cac00..471609aaa 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.Async.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.Async.cs @@ -21,9 +21,9 @@ public async ValueTask OpenEntryStreamAsync( stream = new RarStream( archive.UnpackV1.Value, FileHeader, - await MultiVolumeReadOnlyAsyncStream.Create( - Parts.ToAsyncEnumerable().CastAsync() - ) + await MultiVolumeReadOnlyAsyncStream + .Create(Parts.ToAsyncEnumerable().CastAsync()) + .ConfigureAwait(false) ); } else @@ -31,13 +31,13 @@ await MultiVolumeReadOnlyAsyncStream.Create( stream = new RarStream( archive.UnpackV2017.Value, FileHeader, - await MultiVolumeReadOnlyAsyncStream.Create( - Parts.ToAsyncEnumerable().CastAsync() - ) + await MultiVolumeReadOnlyAsyncStream + .Create(Parts.ToAsyncEnumerable().CastAsync()) + .ConfigureAwait(false) ); } - await stream.InitializeAsync(cancellationToken); + await stream.InitializeAsync(cancellationToken).ConfigureAwait(false); return stream; } } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs index fb430ece8..1f44fa2e5 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Async.cs @@ -21,15 +21,12 @@ private async ValueTask LoadFactoryAsync( { 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 @@ protected override async IAsyncEnumerable LoadEntriesAsync 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/SevenZipArchive.Factory.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Factory.cs index 2748e07c2..76f177fc9 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Factory.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.Factory.cs @@ -147,7 +147,7 @@ public static async ValueTask IsSevenZipFileAsync( cancellationToken.ThrowIfCancellationRequested(); try { - return await SignatureMatchAsync(stream, cancellationToken); + return await SignatureMatchAsync(stream, cancellationToken).ConfigureAwait(false); } catch { diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs index 9d81d04f9..36e3542d5 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs @@ -19,7 +19,10 @@ IReaderOptions readerOptions 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 24a548a8f..1cd7dd91e 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.Async.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.Async.cs @@ -96,7 +96,7 @@ protected override async IAsyncEnumerable LoadEntriesAsync( 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 @@ var header in TarHeaderFactory.ReadHeaderAsync( 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 3a2ba8f34..1290f97a1 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.Factory.cs @@ -166,7 +166,7 @@ public static async ValueTask IsTarFileAsync( #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/Tar/TarArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs index 23471d389..c09d47550 100644 --- a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs @@ -22,7 +22,10 @@ IReaderOptions readerOptions public async ValueTask OpenEntryStreamAsync( CancellationToken cancellationToken = default - ) => (await Parts.Single().GetCompressedStreamAsync(cancellationToken)).NotNull(); + ) => + ( + await Parts.Single().GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false) + ).NotNull(); #region IArchiveEntry Members diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs index 431a4afdd..c8139b067 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs @@ -21,7 +21,7 @@ protected override async IAsyncEnumerable LoadEntriesAsync( 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 4c2163dc9..fb9778a97 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.Factory.cs @@ -203,7 +203,8 @@ public static async ValueTask IsZipFileAsync( var header = await headerFactory .ReadStreamHeaderAsync(stream) .Where(x => x.ZipHeaderType != ZipHeaderType.Split) - .FirstOrDefaultAsync(cancellationToken); + .FirstOrDefaultAsync(cancellationToken) + .ConfigureAwait(false); if (header is null) { return false; @@ -246,6 +247,7 @@ public static async ValueTask IsZipMultiAsync( 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 2d76dcd70..308727a6f 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.Async.cs @@ -15,7 +15,9 @@ public async ValueTask OpenEntryStreamAsync( 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/Ace/Headers/AceFileHeader.Async.cs b/src/SharpCompress/Common/Ace/Headers/AceFileHeader.Async.cs index 07601fdb2..8f8a031e6 100644 --- a/src/SharpCompress/Common/Ace/Headers/AceFileHeader.Async.cs +++ b/src/SharpCompress/Common/Ace/Headers/AceFileHeader.Async.cs @@ -18,7 +18,7 @@ public sealed partial class AceFileHeader CancellationToken cancellationToken = default ) { - var headerData = await ReadHeaderAsync(stream, cancellationToken); + var headerData = await ReadHeaderAsync(stream, cancellationToken).ConfigureAwait(false); if (headerData.Length == 0) { return null; diff --git a/src/SharpCompress/Common/Ace/Headers/AceHeader.Async.cs b/src/SharpCompress/Common/Ace/Headers/AceHeader.Async.cs index 50727a91a..a427ec45a 100644 --- a/src/SharpCompress/Common/Ace/Headers/AceHeader.Async.cs +++ b/src/SharpCompress/Common/Ace/Headers/AceHeader.Async.cs @@ -19,7 +19,9 @@ public async ValueTask ReadHeaderAsync( { // Read header CRC (2 bytes) and header size (2 bytes) var headerBytes = new byte[4]; - if (!await stream.ReadFullyAsync(headerBytes, 0, 4, cancellationToken)) + if ( + !await stream.ReadFullyAsync(headerBytes, 0, 4, cancellationToken).ConfigureAwait(false) + ) { return Array.Empty(); } @@ -33,7 +35,11 @@ public async ValueTask ReadHeaderAsync( // Read the header data var body = new byte[HeaderSize]; - if (!await stream.ReadFullyAsync(body, 0, HeaderSize, cancellationToken)) + if ( + !await stream + .ReadFullyAsync(body, 0, HeaderSize, cancellationToken) + .ConfigureAwait(false) + ) { return Array.Empty(); } @@ -59,7 +65,7 @@ public static async ValueTask IsArchiveAsync( ) { var bytes = new byte[14]; - if (!await stream.ReadFullyAsync(bytes, 0, 14, cancellationToken)) + if (!await stream.ReadFullyAsync(bytes, 0, 14, cancellationToken).ConfigureAwait(false)) { return false; } diff --git a/src/SharpCompress/Common/Ace/Headers/AceMainHeader.Async.cs b/src/SharpCompress/Common/Ace/Headers/AceMainHeader.Async.cs index 10b3f0225..290cd199b 100644 --- a/src/SharpCompress/Common/Ace/Headers/AceMainHeader.Async.cs +++ b/src/SharpCompress/Common/Ace/Headers/AceMainHeader.Async.cs @@ -19,7 +19,7 @@ public sealed partial class AceMainHeader CancellationToken cancellationToken = default ) { - var headerData = await ReadHeaderAsync(stream, cancellationToken); + var headerData = await ReadHeaderAsync(stream, cancellationToken).ConfigureAwait(false); if (headerData.Length == 0) { return null; diff --git a/src/SharpCompress/Common/Arc/ArcEntryHeader.cs b/src/SharpCompress/Common/Arc/ArcEntryHeader.cs index 3645020d0..983b1b785 100644 --- a/src/SharpCompress/Common/Arc/ArcEntryHeader.cs +++ b/src/SharpCompress/Common/Arc/ArcEntryHeader.cs @@ -41,8 +41,9 @@ public ArcEntryHeader(IArchiveEncoding archiveEncoding) { byte[] headerBytes = new byte[29]; if ( - await stream.ReadAsync(headerBytes, 0, headerBytes.Length, cancellationToken) - != headerBytes.Length + await stream + .ReadAsync(headerBytes, 0, headerBytes.Length, cancellationToken) + .ConfigureAwait(false) != headerBytes.Length ) { return null; diff --git a/src/SharpCompress/Common/Arc/ArcFilePart.Async.cs b/src/SharpCompress/Common/Arc/ArcFilePart.Async.cs index 0ae8004db..6b00e3ff5 100644 --- a/src/SharpCompress/Common/Arc/ArcFilePart.Async.cs +++ b/src/SharpCompress/Common/Arc/ArcFilePart.Async.cs @@ -31,11 +31,9 @@ public partial class ArcFilePart compressedStream = new RunLength90Stream(_stream, (int)Header.CompressedSize); break; case CompressionType.Squeezed: - compressedStream = await SqueezeStream.CreateAsync( - _stream, - (int)Header.CompressedSize, - cancellationToken - ); + compressedStream = await SqueezeStream + .CreateAsync(_stream, (int)Header.CompressedSize, cancellationToken) + .ConfigureAwait(false); break; case CompressionType.Crunched: if (Header.OriginalSize > 128 * 1024) diff --git a/src/SharpCompress/Common/Arj/Headers/ArjHeader.Async.cs b/src/SharpCompress/Common/Arj/Headers/ArjHeader.Async.cs index 8f4554449..686d15f51 100644 --- a/src/SharpCompress/Common/Arj/Headers/ArjHeader.Async.cs +++ b/src/SharpCompress/Common/Arj/Headers/ArjHeader.Async.cs @@ -21,7 +21,7 @@ public async ValueTask ReadHeaderAsync( { // check for magic bytes var magic = new byte[2]; - if (await stream.ReadAsync(magic, 0, 2, cancellationToken) != 2) + if (await stream.ReadAsync(magic, 0, 2, cancellationToken).ConfigureAwait(false) != 2) { return Array.Empty(); } @@ -33,7 +33,7 @@ public async ValueTask ReadHeaderAsync( // read header_size byte[] headerBytes = new byte[2]; - await stream.ReadAsync(headerBytes, 0, 2, cancellationToken); + await stream.ReadAsync(headerBytes, 0, 2, cancellationToken).ConfigureAwait(false); var headerSize = (ushort)(headerBytes[0] | headerBytes[1] << 8); if (headerSize < 1) { @@ -41,14 +41,16 @@ public async ValueTask ReadHeaderAsync( } var body = new byte[headerSize]; - var read = await stream.ReadAsync(body, 0, headerSize, cancellationToken); + var read = await stream + .ReadAsync(body, 0, headerSize, cancellationToken) + .ConfigureAwait(false); if (read < headerSize) { return Array.Empty(); } byte[] crc = new byte[4]; - read = await stream.ReadAsync(crc, 0, 4, cancellationToken); + await stream.ReadFullyAsync(crc, 0, 4, cancellationToken).ConfigureAwait(false); var checksum = Crc32Stream.Compute(body); // Compute the hash value if (checksum != BitConverter.ToUInt32(crc, 0)) @@ -68,7 +70,9 @@ protected async ValueTask> ReadExtendedHeadersAsync( while (true) { - int bytesRead = await reader.ReadAsync(buffer, 0, 2, cancellationToken); + int bytesRead = await reader + .ReadAsync(buffer, 0, 2, cancellationToken) + .ConfigureAwait(false); if (bytesRead < 2) { throw new EndOfStreamException( @@ -83,7 +87,9 @@ protected async ValueTask> ReadExtendedHeadersAsync( } byte[] header = new byte[extHeaderSize]; - bytesRead = await reader.ReadAsync(header, 0, extHeaderSize, cancellationToken); + bytesRead = await reader + .ReadAsync(header, 0, extHeaderSize, cancellationToken) + .ConfigureAwait(false); if (bytesRead < extHeaderSize) { throw new EndOfStreamException( @@ -92,7 +98,9 @@ protected async ValueTask> ReadExtendedHeadersAsync( } byte[] crcextended = new byte[4]; - bytesRead = await reader.ReadAsync(crcextended, 0, 4, cancellationToken); + bytesRead = await reader + .ReadAsync(crcextended, 0, 4, cancellationToken) + .ConfigureAwait(false); if (bytesRead < 4) { throw new EndOfStreamException( @@ -122,7 +130,7 @@ public static async ValueTask IsArchiveAsync( ) { var bytes = new byte[2]; - if (await stream.ReadAsync(bytes, 0, 2, cancellationToken) != 2) + if (await stream.ReadAsync(bytes, 0, 2, cancellationToken).ConfigureAwait(false) != 2) { return false; } diff --git a/src/SharpCompress/Common/Arj/Headers/ArjLocalHeader.Async.cs b/src/SharpCompress/Common/Arj/Headers/ArjLocalHeader.Async.cs index eda70ae13..c55583251 100644 --- a/src/SharpCompress/Common/Arj/Headers/ArjLocalHeader.Async.cs +++ b/src/SharpCompress/Common/Arj/Headers/ArjLocalHeader.Async.cs @@ -11,10 +11,10 @@ public partial class ArjLocalHeader CancellationToken cancellationToken = default ) { - var body = await ReadHeaderAsync(stream, cancellationToken); + var body = await ReadHeaderAsync(stream, cancellationToken).ConfigureAwait(false); if (body.Length > 0) { - await ReadExtendedHeadersAsync(stream, cancellationToken); + await ReadExtendedHeadersAsync(stream, cancellationToken).ConfigureAwait(false); var header = LoadFrom(body); header.DataStartPosition = stream.Position; return header; diff --git a/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.Async.cs b/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.Async.cs index cc0592f84..f337b0d3c 100644 --- a/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.Async.cs +++ b/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.Async.cs @@ -11,8 +11,8 @@ public partial class ArjMainHeader CancellationToken cancellationToken = default ) { - var body = await ReadHeaderAsync(stream, cancellationToken); - await ReadExtendedHeadersAsync(stream, cancellationToken); + var body = await ReadHeaderAsync(stream, cancellationToken).ConfigureAwait(false); + await ReadExtendedHeadersAsync(stream, cancellationToken).ConfigureAwait(false); return LoadFrom(body); } } diff --git a/src/SharpCompress/Common/GZip/GZipEntry.Async.cs b/src/SharpCompress/Common/GZip/GZipEntry.Async.cs index dbfade4ab..bdd56dd26 100644 --- a/src/SharpCompress/Common/GZip/GZipEntry.Async.cs +++ b/src/SharpCompress/Common/GZip/GZipEntry.Async.cs @@ -12,7 +12,7 @@ ReaderOptions options ) { yield return new GZipEntry( - await GZipFilePart.CreateAsync(stream, options.ArchiveEncoding), + await GZipFilePart.CreateAsync(stream, options.ArchiveEncoding).ConfigureAwait(false), options ); } diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs b/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs index 34c3c697c..1d56c7bdb 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.Async.cs @@ -19,12 +19,12 @@ internal static async ValueTask CreateAsync( { 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 @@ private async ValueTask ReadTrailerAsync(CancellationToken cancellationToken = d { // 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 @@ private async ValueTask ReadAndValidateGzipHeaderAsync( { // 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 @@ private async ValueTask ReadAndValidateGzipHeaderAsync( { // 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 @@ private async ValueTask ReadZeroTerminatedStringAsync( 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/AsyncRarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/AsyncRarCryptoBinaryReader.cs index d71f35a53..c3f5d005f 100644 --- a/src/SharpCompress/Common/Rar/AsyncRarCryptoBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/AsyncRarCryptoBinaryReader.cs @@ -26,7 +26,9 @@ public static async ValueTask Create( var binary = new AsyncRarCryptoBinaryReader(stream); if (salt == null) { - salt = await binary.ReadBytesAsyncBase(EncryptionConstV5.SIZE_SALT30); + salt = await binary + .ReadBytesAsyncBase(EncryptionConstV5.SIZE_SALT30) + .ConfigureAwait(false); binary._readCount += EncryptionConstV5.SIZE_SALT30; } binary._rijndael = new BlockTransformer(cryptKey.Transformer(salt)); diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs index ef3d4b02b..031fe6bdb 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs @@ -27,6 +27,6 @@ protected sealed override async ValueTask ReadFinishAsync( CancellationToken cancellationToken = default ) { - CryptInfo = await Rar5CryptoInfo.CreateAsync(reader, false); + CryptInfo = await Rar5CryptoInfo.CreateAsync(reader, false).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs index a43ad55b5..a80d121e9 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs @@ -329,7 +329,9 @@ await reader.ReadUInt32Async(cancellationToken).ConfigureAwait(false) if (HasFlag(FileFlagsV4.SALT)) { - R4Salt = await reader.ReadBytesAsync(EncryptionConstV5.SIZE_SALT30, cancellationToken); + R4Salt = await reader + .ReadBytesAsync(EncryptionConstV5.SIZE_SALT30, cancellationToken) + .ConfigureAwait(false); } if (HasFlag(FileFlagsV4.EXT_TIME)) { diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.Async.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.Async.cs index 38b88b254..d020add91 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.Async.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.Async.cs @@ -64,19 +64,19 @@ CancellationToken cancellationToken if (_isRar5 && _cryptInfo != null) { - await _cryptInfo.ReadInitVAsync(new AsyncMarkingBinaryReader(stream)); + await _cryptInfo + .ReadInitVAsync(new AsyncMarkingBinaryReader(stream)) + .ConfigureAwait(false); var _headerKey = new CryptKey5(Options.Password!, _cryptInfo); - reader = await AsyncRarCryptoBinaryReader.Create( - stream, - _headerKey, - _cryptInfo.Salt - ); + reader = await AsyncRarCryptoBinaryReader + .Create(stream, _headerKey, _cryptInfo.Salt) + .ConfigureAwait(false); } else { var key = new CryptKey3(Options.Password); - reader = await AsyncRarCryptoBinaryReader.Create(stream, key); + reader = await AsyncRarCryptoBinaryReader.Create(stream, key).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs b/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs index c02ac5c91..f86e4a38b 100644 --- a/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs +++ b/src/SharpCompress/Common/Rar/Rar5CryptoInfo.cs @@ -57,47 +57,46 @@ bool readInitV ) { 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 @@ public void ReadInitV(MarkingBinaryReader reader) => 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/Rar/RarVolume.cs b/src/SharpCompress/Common/Rar/RarVolume.cs index 4e4fa7700..2e2286d9f 100644 --- a/src/SharpCompress/Common/Rar/RarVolume.cs +++ b/src/SharpCompress/Common/Rar/RarVolume.cs @@ -118,7 +118,8 @@ var header in _headerFactory var buffer = new byte[fh.CompressedSize]; await fh .PackedStream.NotNull() - .ReadFullyAsync(buffer, cancellationToken); + .ReadFullyAsync(buffer, cancellationToken) + .ConfigureAwait(false); Comment = Encoding.UTF8.GetString(buffer, 0, buffer.Length - 1); } } @@ -184,7 +185,7 @@ public bool IsSolidArchive public async ValueTask IsSolidArchiveAsync(CancellationToken cancellationToken = default) { - await EnsureArchiveHeaderLoadedAsync(cancellationToken); + await EnsureArchiveHeaderLoadedAsync(cancellationToken).ConfigureAwait(false); return ArchiveHeader?.IsSolid ?? false; } @@ -248,7 +249,7 @@ private async ValueTask EnsureArchiveHeaderLoadedAsync(CancellationToken cancell } // we only want to load the archive header to avoid overhead but have to do the nasty thing and reset the stream - await GetVolumeFilePartsAsync(cancellationToken).FirstAsync(); + await GetVolumeFilePartsAsync(cancellationToken).FirstAsync().ConfigureAwait(false); Stream.Position = 0; } } diff --git a/src/SharpCompress/Common/SevenZip/ArchiveReader.Async.cs b/src/SharpCompress/Common/SevenZip/ArchiveReader.Async.cs index d065a4bc7..f81c52b99 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveReader.Async.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveReader.Async.cs @@ -29,7 +29,7 @@ public async ValueTask OpenAsync( { // TODO: Check Signature! _header = new byte[0x20]; - await stream.ReadExactAsync(_header, 0, 0x20, cancellationToken); + await stream.ReadExactAsync(_header, 0, 0x20, cancellationToken).ConfigureAwait(false); if ( !lookForHeader @@ -107,7 +107,9 @@ public async ValueTask ReadDatabaseAsync( _stream.Seek(nextHeaderOffset, SeekOrigin.Current); var header = new byte[nextHeaderSize]; - await _stream.ReadExactAsync(header, 0, header.Length, cancellationToken); + await _stream + .ReadExactAsync(header, 0, header.Length, cancellationToken) + .ConfigureAwait(false); if (Crc.Finish(Crc.Update(Crc.INIT_CRC, header, 0, header.Length)) != nextHeaderCrc) { diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index 79155273d..65bb75031 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -68,12 +68,9 @@ internal override Stream GetCompressedStream() { return Stream.Null; } - var folderStream = await _database.GetFolderStreamAsync( - _stream, - Folder!, - _database.PasswordProvider, - cancellationToken - ); + var folderStream = await _database + .GetFolderStreamAsync(_stream, Folder!, _database.PasswordProvider, cancellationToken) + .ConfigureAwait(false); var firstFileIndex = _database._folderStartFileIndex[_database._folders.IndexOf(Folder!)]; var skipCount = Index - firstFileIndex; @@ -84,7 +81,7 @@ internal override Stream GetCompressedStream() } if (skipSize > 0) { - await folderStream.SkipAsync(skipSize, cancellationToken); + await folderStream.SkipAsync(skipSize, cancellationToken).ConfigureAwait(false); } return new ReadOnlySubStream(folderStream, Header.Size, leaveOpen: false); } diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs index f5d796a40..75471aa90 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs @@ -20,10 +20,10 @@ internal async ValueTask WriteAsync( switch (WriteFormat) { case TarHeaderWriteFormat.GNU_TAR_LONG_LINK: - await WriteGnuTarLongLinkAsync(output, cancellationToken); + await WriteGnuTarLongLinkAsync(output, cancellationToken).ConfigureAwait(false); break; case TarHeaderWriteFormat.USTAR: - await WriteUstarAsync(output, cancellationToken); + await WriteUstarAsync(output, cancellationToken).ConfigureAwait(false); break; default: throw new Exception("This should be impossible..."); @@ -162,13 +162,13 @@ CancellationToken cancellationToken if (nameByteCount > 100) { - await WriteLongFilenameHeaderAsync(output, cancellationToken); + await WriteLongFilenameHeaderAsync(output, cancellationToken).ConfigureAwait(false); Name = ArchiveEncoding.Decode( ArchiveEncoding.Encode(Name.NotNull("Name is null")), 0, 100 - ArchiveEncoding.GetEncoding().GetMaxByteCount(1) ); - await WriteGnuTarLongLinkAsync(output, cancellationToken); + await WriteGnuTarLongLinkAsync(output, cancellationToken).ConfigureAwait(false); } } @@ -203,7 +203,7 @@ internal async ValueTask ReadAsync(AsyncBinaryReader reader) do { - buffer = await ReadBlockAsync(reader); + buffer = await ReadBlockAsync(reader).ConfigureAwait(false); if (buffer.Length == 0) { @@ -216,12 +216,12 @@ internal async ValueTask ReadAsync(AsyncBinaryReader reader) // 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 @@ private static async ValueTask ReadBlockAsync(AsyncBinaryReader reader) 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 @@ private async ValueTask ReadLongNameAsync(AsyncBinaryReader reader, byte 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 @@ private async ValueTask ReadLongNameAsync(AsyncBinaryReader reader, byte 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/Tar/TarHeaderFactory.Async.cs b/src/SharpCompress/Common/Tar/TarHeaderFactory.Async.cs index 59e0fc6b5..b0a316f13 100644 --- a/src/SharpCompress/Common/Tar/TarHeaderFactory.Async.cs +++ b/src/SharpCompress/Common/Tar/TarHeaderFactory.Async.cs @@ -25,7 +25,7 @@ IArchiveEncoding archiveEncoding try { header = new TarHeader(archiveEncoding); - if (!await header.ReadAsync(reader)) + if (!await header.ReadAsync(reader).ConfigureAwait(false)) { yield break; } diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.Async.cs index 86e0f771e..40b4ffc78 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 6cc356d6f..c09cac91f 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 9a8a991e2..950494df1 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 9bbfe4f8c..9e5106888 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/Headers/Zip64DirectoryEndLocatorHeader.Async.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.Async.cs index c4188c8b3..e0095510a 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.Async.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.Async.cs @@ -8,8 +8,9 @@ internal partial class Zip64DirectoryEndLocatorHeader { internal override async ValueTask Read(AsyncBinaryReader reader) { - FirstVolumeWithDirectory = await reader.ReadUInt32Async(); - RelativeOffsetOfTheEndOfDirectoryRecord = (long)await reader.ReadUInt64Async(); - TotalNumberOfVolumes = await reader.ReadUInt32Async(); + FirstVolumeWithDirectory = await reader.ReadUInt32Async().ConfigureAwait(false); + RelativeOffsetOfTheEndOfDirectoryRecord = (long) + await reader.ReadUInt64Async().ConfigureAwait(false); + TotalNumberOfVolumes = await reader.ReadUInt32Async().ConfigureAwait(false); } } diff --git a/src/SharpCompress/Common/Zip/SeekableZipFilePart.Async.cs b/src/SharpCompress/Common/Zip/SeekableZipFilePart.Async.cs index 92a8f7b3b..8fff84365 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipFilePart.Async.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipFilePart.Async.cs @@ -13,12 +13,14 @@ internal partial class SeekableZipFilePart { if (!_isLocalHeaderLoaded) { - await LoadLocalHeaderAsync(cancellationToken); + await LoadLocalHeaderAsync(cancellationToken).ConfigureAwait(false); _isLocalHeaderLoaded = true; } - return await base.GetCompressedStreamAsync(cancellationToken); + return await base.GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false); } private async ValueTask LoadLocalHeaderAsync(CancellationToken cancellationToken = default) => - Header = await _headerFactory.GetLocalHeaderAsync(BaseStream, (DirectoryEntryHeader)Header); + Header = await _headerFactory + .GetLocalHeaderAsync(BaseStream, (DirectoryEntryHeader)Header) + .ConfigureAwait(false); } diff --git a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs index 23422ae4f..d7372b00f 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.Async.cs @@ -18,11 +18,11 @@ internal async IAsyncEnumerable ReadSeekableHeaderAsync(Stream stream 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 async IAsyncEnumerable ReadSeekableHeaderAsync(Stream stream // 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 async IAsyncEnumerable ReadSeekableHeaderAsync(Stream stream 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 @@ private static async ValueTask SeekBackToHeaderAsync(Stream stream, AsyncBinaryR 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 @@ DirectoryEntryHeader directoryEntryHeader #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 bcd5650f1..786f22264 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.Async.cs @@ -148,53 +148,63 @@ protected async ValueTask CreateDecompressionStreamAsync( } 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 @@ protected async ValueTask CreateDecompressionStreamAsync( } 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 @@ protected async ValueTask CreateDecompressionStreamAsync( 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: { @@ -284,11 +298,12 @@ await stream } return await CreateDecompressionStreamAsync( - stream, - (ZipCompressionMethod) - BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)), - cancellationToken - ); + stream, + (ZipCompressionMethod) + BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)), + cancellationToken + ) + .ConfigureAwait(false); } default: { diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.Async.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.Async.cs index 8d585505d..c31e24a61 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.Async.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.Async.cs @@ -21,7 +21,7 @@ internal partial class ZipHeaderFactory case ENTRY_HEADER_BYTES: { var entryHeader = new LocalEntryHeader(_archiveEncoding); - await entryHeader.Read(reader); + await entryHeader.Read(reader).ConfigureAwait(false); await LoadHeaderAsync(entryHeader, reader.BaseStream).ConfigureAwait(false); _lastEntryHeader = entryHeader; @@ -30,7 +30,7 @@ internal partial class ZipHeaderFactory case DIRECTORY_START_HEADER_BYTES: { var entry = new DirectoryEntryHeader(_archiveEncoding); - await entry.Read(reader); + await entry.Read(reader).ConfigureAwait(false); return entry; } case POST_DATA_DESCRIPTOR: @@ -43,17 +43,17 @@ internal partial class ZipHeaderFactory ) ) { - _lastEntryHeader.Crc = await reader.ReadUInt32Async(); + _lastEntryHeader.Crc = await reader.ReadUInt32Async().ConfigureAwait(false); _lastEntryHeader.CompressedSize = zip64 - ? (long)await reader.ReadUInt64Async() - : await reader.ReadUInt32Async(); + ? (long)await reader.ReadUInt64Async().ConfigureAwait(false) + : await reader.ReadUInt32Async().ConfigureAwait(false); _lastEntryHeader.UncompressedSize = zip64 - ? (long)await reader.ReadUInt64Async() - : await reader.ReadUInt32Async(); + ? (long)await reader.ReadUInt64Async().ConfigureAwait(false) + : await reader.ReadUInt32Async().ConfigureAwait(false); } else { - await reader.SkipAsync(zip64 ? 20 : 12); + await reader.SkipAsync(zip64 ? 20 : 12).ConfigureAwait(false); } return null; } @@ -62,7 +62,7 @@ internal partial class ZipHeaderFactory case DIRECTORY_END_HEADER_BYTES: { var entry = new DirectoryEndHeader(); - await entry.Read(reader); + await entry.Read(reader).ConfigureAwait(false); return entry; } case SPLIT_ARCHIVE_HEADER_BYTES: @@ -72,13 +72,13 @@ internal partial class ZipHeaderFactory case ZIP64_END_OF_CENTRAL_DIRECTORY: { var entry = new Zip64DirectoryEndHeader(); - await entry.Read(reader); + await entry.Read(reader).ConfigureAwait(false); return entry; } case ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR: { var entry = new Zip64DirectoryEndLocatorHeader(); - await entry.Read(reader); + await entry.Read(reader).ConfigureAwait(false); return entry; } default: diff --git a/src/SharpCompress/Compressors/ADC/ADCBase.Async.cs b/src/SharpCompress/Compressors/ADC/ADCBase.Async.cs index 5ef29c2a2..7bbbacdee 100644 --- a/src/SharpCompress/Compressors/ADC/ADCBase.Async.cs +++ b/src/SharpCompress/Compressors/ADC/ADCBase.Async.cs @@ -19,7 +19,9 @@ public static async ValueTask DecompressAsync( byte[] input, int bufferSize = 262144, CancellationToken cancellationToken = default - ) => await DecompressAsync(new MemoryStream(input), bufferSize, cancellationToken); + ) => + await DecompressAsync(new MemoryStream(input), bufferSize, cancellationToken) + .ConfigureAwait(false); /// /// Decompresses a stream asynchronously that's compressed with ADC @@ -76,12 +78,9 @@ public static async ValueTask DecompressAsync( break; } - var readCount = await input.ReadAsync( - buffer, - outPosition, - chunkSize, - cancellationToken - ); + var readCount = await input + .ReadAsync(buffer, outPosition, chunkSize, cancellationToken) + .ConfigureAwait(false); outPosition += readCount; position += readCount + 1; break; diff --git a/src/SharpCompress/Compressors/ADC/ADCStream.Async.cs b/src/SharpCompress/Compressors/ADC/ADCStream.Async.cs index cf12a8c70..22941be58 100644 --- a/src/SharpCompress/Compressors/ADC/ADCStream.Async.cs +++ b/src/SharpCompress/Compressors/ADC/ADCStream.Async.cs @@ -66,10 +66,9 @@ public override async Task ReadAsync( if (_outBuffer is null) { - var result = await ADCBase.DecompressAsync( - _stream, - cancellationToken: cancellationToken - ); + var result = await ADCBase + .DecompressAsync(_stream, cancellationToken: cancellationToken) + .ConfigureAwait(false); _outBuffer = result.Output; _outPosition = 0; } @@ -87,10 +86,9 @@ public override async Task ReadAsync( copied += piece; _position += piece; toCopy -= piece; - var result = await ADCBase.DecompressAsync( - _stream, - cancellationToken: cancellationToken - ); + var result = await ADCBase + .DecompressAsync(_stream, cancellationToken: cancellationToken) + .ConfigureAwait(false); _outBuffer = result.Output; _outPosition = 0; if (result.BytesRead == 0 || _outBuffer is null || _outBuffer.Length == 0) diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Stream.Async.cs b/src/SharpCompress/Compressors/BZip2/BZip2Stream.Async.cs index c9b0b0319..d14e21591 100644 --- a/src/SharpCompress/Compressors/BZip2/BZip2Stream.Async.cs +++ b/src/SharpCompress/Compressors/BZip2/BZip2Stream.Async.cs @@ -31,12 +31,9 @@ public static async ValueTask CreateAsync( } else { - bZip2Stream.stream = await CBZip2InputStream.CreateAsync( - stream, - decompressConcatenated, - leaveOpen, - cancellationToken - ); + bZip2Stream.stream = await CBZip2InputStream + .CreateAsync(stream, decompressConcatenated, leaveOpen, cancellationToken) + .ConfigureAwait(false); } return bZip2Stream; @@ -55,7 +52,9 @@ public static async ValueTask IsBZip2Async( { cancellationToken.ThrowIfCancellationRequested(); var buffer = new byte[2]; - var bytesRead = await stream.ReadAsync(buffer, 0, 2, cancellationToken); + var bytesRead = await stream + .ReadAsync(buffer, 0, 2, cancellationToken) + .ConfigureAwait(false); if (bytesRead < 2 || buffer[0] != 'B' || buffer[1] != 'Z') { return false; diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.Async.cs b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.Async.cs index 6a5992e81..8b2c45af9 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.Async.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.Async.cs @@ -800,14 +800,6 @@ public override async Task ReadAsync( return k; } - private async ValueTask BsSetStreamAsync(Stream f, CancellationToken cancellationToken) - { - bsStream = f; - bsLive = 0; - bsBuff = 0; - await Task.CompletedTask; - } - private async ValueTask BsRAsync(int n, CancellationToken cancellationToken) { int v; @@ -818,7 +810,7 @@ private async ValueTask BsRAsync(int n, CancellationToken cancellationToken var b = ArrayPool.Shared.Rent(1); try { - await bsStream.ReadExactAsync(b, 0, 1, cancellationToken); + await bsStream.ReadExactAsync(b, 0, 1, cancellationToken).ConfigureAwait(false); thech = (char)b[0]; } catch (IOException) @@ -844,15 +836,15 @@ private async ValueTask BsRAsync(int n, CancellationToken cancellationToken } private async ValueTask BsGetUCharAsync(CancellationToken cancellationToken) => - (char)await BsRAsync(8, cancellationToken); + (char)await BsRAsync(8, cancellationToken).ConfigureAwait(false); private async ValueTask BsGetIntVSAsync( int numBits, CancellationToken cancellationToken - ) => await BsRAsync(numBits, cancellationToken); + ) => await BsRAsync(numBits, cancellationToken).ConfigureAwait(false); private async ValueTask BsGetInt32Async(CancellationToken cancellationToken) => - await BsGetintAsync(cancellationToken); + await BsGetintAsync(cancellationToken).ConfigureAwait(false); public static async ValueTask CreateAsync( Stream zStream, @@ -864,10 +856,10 @@ public static async ValueTask CreateAsync( var cbZip2InputStream = new CBZip2InputStream(decompressConcatenated, leaveOpen); cbZip2InputStream.ll8 = null; cbZip2InputStream.tt = null; - await cbZip2InputStream.BsSetStreamAsync(zStream, cancellationToken); - await cbZip2InputStream.InitializeAsync(true, cancellationToken); - await cbZip2InputStream.InitBlockAsync(cancellationToken); - await cbZip2InputStream.SetupBlockAsync(cancellationToken); + cbZip2InputStream.BsSetStream(zStream); + await cbZip2InputStream.InitializeAsync(true, cancellationToken).ConfigureAwait(false); + await cbZip2InputStream.InitBlockAsync(cancellationToken).ConfigureAwait(false); + await cbZip2InputStream.SetupBlockAsync(cancellationToken).ConfigureAwait(false); return cbZip2InputStream; } } diff --git a/src/SharpCompress/Compressors/LZMA/DecoderRegistry.Async.cs b/src/SharpCompress/Compressors/LZMA/DecoderRegistry.Async.cs index 5a3a3fcd7..a3d3a2ea9 100644 --- a/src/SharpCompress/Compressors/LZMA/DecoderRegistry.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/DecoderRegistry.Async.cs @@ -60,12 +60,14 @@ CancellationToken cancellationToken case K_RISCV: return new BCJFilterRISCV(false, inStreams.Single()); case K_B_ZIP2: - return await BZip2Stream.CreateAsync( - inStreams.Single(), - CompressionMode.Decompress, - true, - cancellationToken: cancellationToken - ); + return await BZip2Stream + .CreateAsync( + inStreams.Single(), + CompressionMode.Decompress, + true, + cancellationToken: cancellationToken + ) + .ConfigureAwait(false); case K_PPMD: return await PpmdStream .CreateAsync( diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.Async.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.Async.cs index ecf82e2e7..011fdf2e4 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.Async.cs @@ -12,7 +12,7 @@ internal partial class OutWindow : IAsyncDisposable { public async ValueTask InitAsync(Stream stream) { - await ReleaseStreamAsync(); + await ReleaseStreamAsync().ConfigureAwait(false); _stream = stream; } @@ -24,7 +24,7 @@ public async ValueTask ReleaseStreamAsync(CancellationToken cancellationToken = public async ValueTask DisposeAsync() { - await ReleaseStreamAsync(); + await ReleaseStreamAsync().ConfigureAwait(false); if (_buffer is null) { return; @@ -167,7 +167,7 @@ public async ValueTask TrainAsync(Stream stream) _total = 0; _limit = size; _pos = _windowSize - size; - await CopyStreamAsync(stream, size); + await CopyStreamAsync(stream, size).ConfigureAwait(false); if (_pos == _windowSize) { _pos = 0; diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.Async.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.Async.cs index f83cbff9d..0a85a3783 100644 --- a/src/SharpCompress/Compressors/LZMA/LZipStream.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/LZipStream.Async.cs @@ -20,7 +20,7 @@ public sealed partial class LZipStream public static async ValueTask IsLZipFileAsync( Stream stream, CancellationToken cancellationToken = default - ) => await ValidateAndReadSizeAsync(stream, cancellationToken) != 0; + ) => await ValidateAndReadSizeAsync(stream, cancellationToken).ConfigureAwait(false) != 0; /// /// Asynchronously reads the 6-byte header of the stream, and returns 0 if either the header @@ -91,7 +91,7 @@ CancellationToken cancellationToken ) { cancellationToken.ThrowIfCancellationRequested(); - await _stream.WriteAsync(buffer, offset, count, cancellationToken); + await _stream.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); _writeCount += count; } } diff --git a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs index add73b8e8..b1d061e89 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.Async.cs @@ -137,7 +137,7 @@ public async Task CodeAsync( { CreateDictionary(); } - await _outWindow.InitAsync(outStream); + await _outWindow.InitAsync(outStream).ConfigureAwait(false); if (outSize > 0) { _outWindow.SetLimit(outSize); @@ -178,29 +178,34 @@ internal async ValueTask CodeAsync( 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 @@ await _isMatchDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posSt { 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 @@ await outWindow uint distance; if ( await _isRepG1Decoders[_state._index] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { distance = _rep1; @@ -246,7 +255,8 @@ await _isRepG1Decoders[_state._index] { if ( await _isRepG2Decoders[_state._index] - .DecodeAsync(rangeDecoder, cancellationToken) == 0 + .DecodeAsync(rangeDecoder, cancellationToken) + .ConfigureAwait(false) == 0 ) { distance = _rep2; @@ -339,6 +349,6 @@ public async ValueTask TrainAsync(Stream stream) { CreateDictionary(); } - await _outWindow.TrainAsync(stream); + await _outWindow.TrainAsync(stream).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Compressors/LZMA/LzmaStream.Async.cs b/src/SharpCompress/Compressors/LZMA/LzmaStream.Async.cs index 0187a6849..6167c8b2e 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaStream.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaStream.Async.cs @@ -47,16 +47,16 @@ public static async ValueTask CreateAsync( { if (presetDictionary != null) { - await lzma._outWindow.TrainAsync(presetDictionary); + await lzma._outWindow.TrainAsync(presetDictionary).ConfigureAwait(false); } - await lzma._rangeDecoder.InitAsync(inputStream); + await lzma._rangeDecoder.InitAsync(inputStream).ConfigureAwait(false); } else { if (presetDictionary != null) { - await lzma._outWindow.TrainAsync(presetDictionary); + await lzma._outWindow.TrainAsync(presetDictionary).ConfigureAwait(false); lzma._needDictReset = false; } } @@ -147,7 +147,7 @@ await _inputStream! _decoder.SetDecoderProperties(Properties); } - await _rangeDecoder.InitAsync(_inputStream, cancellationToken); + await _rangeDecoder.InitAsync(_inputStream, cancellationToken).ConfigureAwait(false); } else if (control > 0x02) { diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.Async.cs b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.Async.cs index cca7b2ddc..8ba2901b2 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.Async.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.Async.cs @@ -22,6 +22,6 @@ public override async Task WriteAsync( Processed += count; _mCrc = Crc.Update(_mCrc, buffer, offset, count); - await _mTarget.WriteAsync(buffer, offset, count, cancellationToken); + await _mTarget.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); } } diff --git a/src/SharpCompress/Compressors/Lzw/LzwStream.Async.cs b/src/SharpCompress/Compressors/Lzw/LzwStream.Async.cs index 063b9df9d..c6103e101 100644 --- a/src/SharpCompress/Compressors/Lzw/LzwStream.Async.cs +++ b/src/SharpCompress/Compressors/Lzw/LzwStream.Async.cs @@ -24,7 +24,9 @@ public static async ValueTask IsLzwStreamAsync( { byte[] hdr = new byte[LzwConstants.HDR_SIZE]; - int result = await stream.ReadAsync(hdr, 0, hdr.Length, cancellationToken); + int result = await stream + .ReadAsync(hdr, 0, hdr.Length, cancellationToken) + .ConfigureAwait(false); // Check the magic marker if (result < 0) diff --git a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyAsyncStream.Async.cs b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyAsyncStream.Async.cs index e0b347201..64f461d43 100644 --- a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyAsyncStream.Async.cs +++ b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyAsyncStream.Async.cs @@ -15,7 +15,7 @@ IAsyncEnumerable parts ) { var stream = new MultiVolumeReadOnlyAsyncStream(parts); - await stream.filePartEnumerator.MoveNextAsync(); + await stream.filePartEnumerator.MoveNextAsync().ConfigureAwait(false); stream.InitializeNextFilePart(); return stream; } @@ -23,10 +23,10 @@ IAsyncEnumerable parts #if NET8_0_OR_GREATER public override async ValueTask DisposeAsync() { - await base.DisposeAsync(); + await base.DisposeAsync().ConfigureAwait(false); if (filePartEnumerator != null) { - await filePartEnumerator.DisposeAsync(); + await filePartEnumerator.DisposeAsync().ConfigureAwait(false); } currentStream = null; } @@ -85,7 +85,7 @@ CancellationToken cancellationToken } var fileName = filePartEnumerator.Current.FileHeader.FileName; - if (!await filePartEnumerator.MoveNextAsync()) + if (!await filePartEnumerator.MoveNextAsync().ConfigureAwait(false)) { throw new InvalidFormatException( "Multi-part rar file is incomplete. Entry expects a new volume: " @@ -146,7 +146,7 @@ public override async ValueTask ReadAsync( ); } var fileName = filePartEnumerator.Current.FileHeader.FileName; - if (!await filePartEnumerator.MoveNextAsync()) + if (!await filePartEnumerator.MoveNextAsync().ConfigureAwait(false)) { throw new InvalidFormatException( "Multi-part rar file is incomplete. Entry expects a new volume: " diff --git a/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.Async.cs b/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.Async.cs index 4015b4201..6b44acb37 100644 --- a/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.Async.cs +++ b/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.Async.cs @@ -17,7 +17,7 @@ public static async ValueTask CreateAsync( ) { var stream = new RarBLAKE2spStream(unpack, fileHeader, readStream); - await stream.InitializeAsync(cancellationToken); + await stream.InitializeAsync(cancellationToken).ConfigureAwait(false); return stream; } diff --git a/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs b/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs index f49f63ba8..670ff8b84 100644 --- a/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs +++ b/src/SharpCompress/Compressors/Rar/RarCrcStream.Async.cs @@ -17,7 +17,7 @@ public static async ValueTask CreateAsync( ) { var stream = new RarCrcStream(unpack, fileHeader, readStream); - await stream.InitializeAsync(cancellationToken); + await stream.InitializeAsync(cancellationToken).ConfigureAwait(false); return stream; } diff --git a/src/SharpCompress/Compressors/Rar/RarStream.Async.cs b/src/SharpCompress/Compressors/Rar/RarStream.Async.cs index 4ea0651dc..444da3e7d 100644 --- a/src/SharpCompress/Compressors/Rar/RarStream.Async.cs +++ b/src/SharpCompress/Compressors/Rar/RarStream.Async.cs @@ -18,7 +18,9 @@ internal partial class RarStream public async ValueTask InitializeAsync(CancellationToken cancellationToken = default) { fetch = true; - await unpack.DoUnpackAsync(fileHeader, readStream, this, cancellationToken); + await unpack + .DoUnpackAsync(fileHeader, readStream, this, cancellationToken) + .ConfigureAwait(false); fetch = false; _position = 0; } diff --git a/src/SharpCompress/Compressors/ZStandard/ZStandardStream.Async.cs b/src/SharpCompress/Compressors/ZStandard/ZStandardStream.Async.cs index abef7d421..f59326196 100644 --- a/src/SharpCompress/Compressors/ZStandard/ZStandardStream.Async.cs +++ b/src/SharpCompress/Compressors/ZStandard/ZStandardStream.Async.cs @@ -15,7 +15,9 @@ internal static async ValueTask IsZStandardAsync( { cancellationToken.ThrowIfCancellationRequested(); var buffer = new byte[4]; - var bytesRead = await stream.ReadAsync(buffer, 0, 4, cancellationToken); + var bytesRead = await stream + .ReadAsync(buffer, 0, 4, cancellationToken) + .ConfigureAwait(false); if (bytesRead < 4) { return false; diff --git a/src/SharpCompress/Factories/ArcFactory.cs b/src/SharpCompress/Factories/ArcFactory.cs index 75558ce70..46c126666 100644 --- a/src/SharpCompress/Factories/ArcFactory.cs +++ b/src/SharpCompress/Factories/ArcFactory.cs @@ -76,7 +76,7 @@ public override async ValueTask IsArchiveAsync( var buffer = ArrayPool.Shared.Rent(2); try { - await stream.ReadExactAsync(buffer, 0, 2, cancellationToken); + await stream.ReadExactAsync(buffer, 0, 2, cancellationToken).ConfigureAwait(false); return buffer[0] == 0x1A && buffer[1] < 10; //rather thin, but this is all we have } finally diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index 233a51841..abc800e11 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -82,14 +82,21 @@ public override async ValueTask IsArchiveAsync( 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; @@ -189,14 +196,21 @@ public async ValueTask OpenAsyncReader( 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/TarWrapper.cs b/src/SharpCompress/Factories/TarWrapper.cs index 2f3ff64a3..fee9707e1 100644 --- a/src/SharpCompress/Factories/TarWrapper.cs +++ b/src/SharpCompress/Factories/TarWrapper.cs @@ -54,7 +54,9 @@ public class TarWrapper( BZip2Stream.IsBZip2Async, (stream) => BZip2Stream.Create(stream, CompressionMode.Decompress, false), async (stream, _) => - await BZip2Stream.CreateAsync(stream, CompressionMode.Decompress, false), + await BZip2Stream + .CreateAsync(stream, CompressionMode.Decompress, false) + .ConfigureAwait(false), ["tar.bz2", "tb2", "tbz", "tbz2", "tz2"] ), new( diff --git a/src/SharpCompress/Factories/ZipFactory.cs b/src/SharpCompress/Factories/ZipFactory.cs index 6d984259c..6b7df689a 100644 --- a/src/SharpCompress/Factories/ZipFactory.cs +++ b/src/SharpCompress/Factories/ZipFactory.cs @@ -82,7 +82,11 @@ public override async ValueTask IsArchiveAsync( 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 override async ValueTask IsArchiveAsync( 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/IO/SharpCompressStream.Async.cs b/src/SharpCompress/IO/SharpCompressStream.Async.cs index 3544a649b..e18a47a19 100644 --- a/src/SharpCompress/IO/SharpCompressStream.Async.cs +++ b/src/SharpCompress/IO/SharpCompressStream.Async.cs @@ -243,9 +243,16 @@ CancellationToken cancellationToken { byte[] buffer = new byte[bufferSize]; int bytesRead; - while ((bytesRead = await ReadAsync(buffer, 0, buffer.Length, cancellationToken)) != 0) + while ( + ( + bytesRead = await ReadAsync(buffer, 0, buffer.Length, cancellationToken) + .ConfigureAwait(false) + ) != 0 + ) { - await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken); + await destination + .WriteAsync(buffer, 0, bytesRead, cancellationToken) + .ConfigureAwait(false); } } @@ -263,7 +270,7 @@ public override async ValueTask DisposeAsync() isDisposed = true; if (!LeaveStreamOpen) { - await stream.DisposeAsync(); + await stream.DisposeAsync().ConfigureAwait(false); } _ringBuffer?.Dispose(); _ringBuffer = null; diff --git a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs index 114bc71a1..6d1525936 100644 --- a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs +++ b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs @@ -41,7 +41,7 @@ public async ValueTask MoveNextAsync() } if ( !lazyReadOnlyCollection._fullyLoaded - && await lazyReadOnlyCollection._source.MoveNextAsync() + && await lazyReadOnlyCollection._source.MoveNextAsync().ConfigureAwait(false) ) { lazyReadOnlyCollection._backing.Add(lazyReadOnlyCollection._source.Current); @@ -76,7 +76,7 @@ internal async ValueTask EnsureFullyLoaded() 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/Polyfills/AsyncEnumerableExtensions.cs b/src/SharpCompress/Polyfills/AsyncEnumerableExtensions.cs index 9d0dad0a8..6df982a04 100644 --- a/src/SharpCompress/Polyfills/AsyncEnumerableExtensions.cs +++ b/src/SharpCompress/Polyfills/AsyncEnumerableExtensions.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -12,7 +10,7 @@ public static class AsyncEnumerableEx public static async IAsyncEnumerable Empty() where T : notnull { - await Task.CompletedTask; + await Task.Yield(); yield break; } } @@ -21,7 +19,7 @@ public static class EnumerableExtensions { public static async IAsyncEnumerable ToAsyncEnumerable(this IEnumerable source) { - await Task.CompletedTask; + await Task.Yield(); foreach (var item in source) { yield return item; @@ -47,7 +45,7 @@ public async ValueTask CountAsync(CancellationToken cancellationToken = def await using var e = source.GetAsyncEnumerator(cancellationToken); var count = 0; - while (await e.MoveNextAsync()) + while (await e.MoveNextAsync().ConfigureAwait(false)) { checked { @@ -117,12 +115,12 @@ public async ValueTask SingleAsync(Func? predicate = null) enumerator = source.Where(predicate).GetAsyncEnumerator(); } - if (!await enumerator.MoveNextAsync()) + if (!await enumerator.MoveNextAsync().ConfigureAwait(false)) { throw new InvalidOperationException("The source sequence is empty."); } var value = enumerator.Current; - if (await enumerator.MoveNextAsync()) + if (await enumerator.MoveNextAsync().ConfigureAwait(false)) { throw new InvalidOperationException( "The source sequence contains more than one element." diff --git a/src/SharpCompress/Readers/AbstractReader.Async.cs b/src/SharpCompress/Readers/AbstractReader.Async.cs index 958045e03..dc73e6fcc 100644 --- a/src/SharpCompress/Readers/AbstractReader.Async.cs +++ b/src/SharpCompress/Readers/AbstractReader.Async.cs @@ -17,13 +17,13 @@ public virtual async ValueTask DisposeAsync() { 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 async ValueTask MoveToNextEntryAsync(CancellationToken cancellation } 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 @@ protected async ValueTask LoadStreamForReadingAsync(Stream stream) { if (_entriesForCurrentReadStreamAsync is not null) { - await _entriesForCurrentReadStreamAsync.DisposeAsync(); + await _entriesForCurrentReadStreamAsync.DisposeAsync().ConfigureAwait(false); } if (stream is null || !stream.CanRead) { @@ -73,7 +73,7 @@ protected async ValueTask LoadStreamForReadingAsync(Stream stream) ); } _entriesForCurrentReadStreamAsync = GetEntriesAsync(stream).GetAsyncEnumerator(); - return await _entriesForCurrentReadStreamAsync.MoveNextAsync(); + return await _entriesForCurrentReadStreamAsync.MoveNextAsync().ConfigureAwait(false); } private async ValueTask SkipEntryAsync(CancellationToken cancellationToken) @@ -202,7 +202,6 @@ CancellationToken cancellationToken // Async iterator method protected virtual async IAsyncEnumerable GetEntriesAsync(Stream stream) { - await Task.CompletedTask; foreach (var entry in GetEntries(stream)) { yield return entry; diff --git a/src/SharpCompress/Readers/Ace/AceReader.cs b/src/SharpCompress/Readers/Ace/AceReader.cs index 854af4ed3..351e85669 100644 --- a/src/SharpCompress/Readers/Ace/AceReader.cs +++ b/src/SharpCompress/Readers/Ace/AceReader.cs @@ -88,7 +88,7 @@ protected override async IAsyncEnumerable GetEntriesAsync(Stream strea } var mainHeaderReader = new AceMainHeader(_archiveEncoding); - var mainHeader = await mainHeaderReader.ReadAsync(stream); + var mainHeader = await mainHeaderReader.ReadAsync(stream).ConfigureAwait(false); if (mainHeader == null) { yield break; @@ -102,7 +102,7 @@ protected override async IAsyncEnumerable GetEntriesAsync(Stream strea var localHeaderReader = new AceFileHeader(_archiveEncoding); while (true) { - var localHeader = await localHeaderReader.ReadAsync(stream); + var localHeader = await localHeaderReader.ReadAsync(stream).ConfigureAwait(false); if (localHeader?.IsFileEncrypted == true) { throw new CryptographicException( diff --git a/src/SharpCompress/Readers/Arc/ArcReader.Async.cs b/src/SharpCompress/Readers/Arc/ArcReader.Async.cs index dc843e9e8..004135cd8 100644 --- a/src/SharpCompress/Readers/Arc/ArcReader.Async.cs +++ b/src/SharpCompress/Readers/Arc/ArcReader.Async.cs @@ -12,7 +12,11 @@ protected override async IAsyncEnumerable GetEntriesAsync(Stream strea ArcEntryHeader headerReader = new ArcEntryHeader(Options.ArchiveEncoding); ArcEntryHeader? header; while ( - (header = await headerReader.ReadHeaderAsync(stream, CancellationToken.None)) != null + ( + header = await headerReader + .ReadHeaderAsync(stream, CancellationToken.None) + .ConfigureAwait(false) + ) != null ) { yield return new ArcEntry(new ArcFilePart(header, stream), Options); diff --git a/src/SharpCompress/Readers/Arj/ArjReader.cs b/src/SharpCompress/Readers/Arj/ArjReader.cs index 5c751cebc..857a5ec90 100644 --- a/src/SharpCompress/Readers/Arj/ArjReader.cs +++ b/src/SharpCompress/Readers/Arj/ArjReader.cs @@ -103,7 +103,7 @@ protected override async IAsyncEnumerable GetEntriesAsync(Stream strea var mainHeaderReader = new ArjMainHeader(encoding); var localHeaderReader = new ArjLocalHeader(encoding); - var mainHeader = await mainHeaderReader.ReadAsync(stream); + var mainHeader = await mainHeaderReader.ReadAsync(stream).ConfigureAwait(false); if (mainHeader?.IsVolume == true) { throw new MultiVolumeExtractionException("Multi volumes are currently not supported"); @@ -123,7 +123,7 @@ protected override async IAsyncEnumerable GetEntriesAsync(Stream strea while (true) { - var localHeader = await localHeaderReader.ReadAsync(stream); + var localHeader = await localHeaderReader.ReadAsync(stream).ConfigureAwait(false); if (localHeader == null) { break; diff --git a/src/SharpCompress/Readers/IAsyncReaderExtensions.cs b/src/SharpCompress/Readers/IAsyncReaderExtensions.cs index cb1e0fbbf..07a7db8dd 100644 --- a/src/SharpCompress/Readers/IAsyncReaderExtensions.cs +++ b/src/SharpCompress/Readers/IAsyncReaderExtensions.cs @@ -54,7 +54,7 @@ public async ValueTask WriteAllToDirectoryAsync( CancellationToken cancellationToken = default ) { - while (await reader.MoveToNextEntryAsync(cancellationToken)) + while (await reader.MoveToNextEntryAsync(cancellationToken).ConfigureAwait(false)) { await reader .WriteEntryToDirectoryAsync(destinationDirectory, cancellationToken) diff --git a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs index 7107adbaf..1f9d4463f 100644 --- a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs +++ b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs @@ -57,7 +57,7 @@ public async ValueTask MoveNextAsync() } if (tempStream != null) { - await reader.LoadStreamForReadingAsync(tempStream); + await reader.LoadStreamForReadingAsync(tempStream).ConfigureAwait(false); tempStream = null; } else if (!nextReadableStreams.MoveNext()) @@ -68,7 +68,9 @@ public async ValueTask MoveNextAsync() } else { - await reader.LoadStreamForReadingAsync(nextReadableStreams.Current); + await reader + .LoadStreamForReadingAsync(nextReadableStreams.Current) + .ConfigureAwait(false); } Current = reader.Entry.Parts.First(); diff --git a/src/SharpCompress/Readers/Rar/RarReader.Async.cs b/src/SharpCompress/Readers/Rar/RarReader.Async.cs index 0e1943d23..9ccc5231f 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.Async.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.Async.cs @@ -32,9 +32,9 @@ protected override async ValueTask GetEntryStreamAsync( throw new InvalidOperationException("no stream for redirect entry"); } - var stream = await MultiVolumeReadOnlyAsyncStream.Create( - CreateFilePartEnumerableForCurrentEntryAsync().CastAsync() - ); + var stream = await MultiVolumeReadOnlyAsyncStream + .Create(CreateFilePartEnumerableForCurrentEntryAsync().CastAsync()) + .ConfigureAwait(false); if (Entry.IsRarV3) { return CreateEntryStream( diff --git a/src/SharpCompress/Readers/ReaderFactory.Async.cs b/src/SharpCompress/Readers/ReaderFactory.Async.cs index 58ca951d1..c74a7133e 100644 --- a/src/SharpCompress/Readers/ReaderFactory.Async.cs +++ b/src/SharpCompress/Readers/ReaderFactory.Async.cs @@ -73,19 +73,16 @@ public static async ValueTask OpenAsyncReader( { sharpCompressStream.Rewind(); if ( - await testedFactory.IsArchiveAsync( - sharpCompressStream, - cancellationToken: cancellationToken - ) + await testedFactory + .IsArchiveAsync(sharpCompressStream, cancellationToken: cancellationToken) + .ConfigureAwait(false) ) { sharpCompressStream.Rewind(); sharpCompressStream.StopRecording(); - return await readerFactory.OpenAsyncReader( - sharpCompressStream, - options, - cancellationToken - ); + return await readerFactory + .OpenAsyncReader(sharpCompressStream, options, cancellationToken) + .ConfigureAwait(false); } } sharpCompressStream.Rewind(); @@ -100,19 +97,16 @@ await testedFactory.IsArchiveAsync( sharpCompressStream.Rewind(); if ( factory is IReaderFactory readerFactory - && await factory.IsArchiveAsync( - sharpCompressStream, - cancellationToken: cancellationToken - ) + && await factory + .IsArchiveAsync(sharpCompressStream, cancellationToken: cancellationToken) + .ConfigureAwait(false) ) { sharpCompressStream.Rewind(); sharpCompressStream.StopRecording(); - return await readerFactory.OpenAsyncReader( - sharpCompressStream, - options, - cancellationToken - ); + return await readerFactory + .OpenAsyncReader(sharpCompressStream, options, cancellationToken) + .ConfigureAwait(false); } } diff --git a/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs b/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs index 81b9d8256..478373aa6 100644 --- a/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs +++ b/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs @@ -24,9 +24,9 @@ public override async ValueTask WriteAsync( stream.LastModified = modificationTime; var progressStream = WrapWithProgress(source, filename); #if LEGACY_DOTNET - await progressStream.CopyToAsync(stream); + await progressStream.CopyToAsync(stream).ConfigureAwait(false); #else - await progressStream.CopyToAsync(stream, cancellationToken); + await progressStream.CopyToAsync(stream, cancellationToken).ConfigureAwait(false); #endif _wroteToStream = true; } diff --git a/src/SharpCompress/Writers/Tar/TarWriter.Async.cs b/src/SharpCompress/Writers/Tar/TarWriter.Async.cs index 5cc6c6220..db5e00d4e 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.Async.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.Async.cs @@ -40,7 +40,9 @@ public override async ValueTask WriteAsync( Stream source, DateTime? modificationTime, CancellationToken cancellationToken = default - ) => await WriteAsync(filename, source, modificationTime, null, cancellationToken); + ) => + await WriteAsync(filename, source, modificationTime, null, cancellationToken) + .ConfigureAwait(false); /// /// Asynchronously writes a file entry with optional size specification.