mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 16:05:27 +00:00
first round of configure await false
This commit is contained in:
@@ -21,7 +21,7 @@ public abstract partial class AbstractArchive<TEntry, TVolume>
|
||||
IAsyncEnumerable<TVolume> volumes
|
||||
)
|
||||
{
|
||||
foreach (var item in LoadEntries(await volumes.ToListAsync()))
|
||||
foreach (var item in LoadEntries(await volumes.ToListAsync().ConfigureAwait(false)))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
@@ -47,8 +47,8 @@ public abstract partial class AbstractArchive<TEntry, TVolume>
|
||||
|
||||
private async ValueTask EnsureEntriesLoadedAsync()
|
||||
{
|
||||
await _lazyEntriesAsync.EnsureFullyLoaded();
|
||||
await _lazyVolumesAsync.EnsureFullyLoaded();
|
||||
await _lazyEntriesAsync.EnsureFullyLoaded().ConfigureAwait(false);
|
||||
await _lazyVolumesAsync.EnsureFullyLoaded().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async IAsyncEnumerable<IArchiveEntry> EntriesAsyncCast()
|
||||
@@ -73,29 +73,31 @@ public abstract partial class AbstractArchive<TEntry, TVolume>
|
||||
|
||||
public async ValueTask<IAsyncReader> 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<bool> IsSolidAsync() => new(false);
|
||||
|
||||
public async ValueTask<bool> 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<long> TotalSizeAsync() =>
|
||||
await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.CompressedSize);
|
||||
await EntriesAsync
|
||||
.AggregateAsync(0L, (total, cf) => total + cf.CompressedSize)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
public async ValueTask<long> TotalUncompressedSizeAsync() =>
|
||||
await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.Size);
|
||||
await EntriesAsync.AggregateAsync(0L, (total, cf) => total + cf.Size).ConfigureAwait(false);
|
||||
|
||||
public ValueTask<bool> IsEncryptedAsync() => new(IsEncrypted);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract partial class AbstractWritableArchive<TEntry, TVolume, TOptions>
|
||||
if (!removedEntries.Contains(entry))
|
||||
{
|
||||
removedEntries.Add(entry);
|
||||
await RebuildModifiedCollectionAsync();
|
||||
await RebuildModifiedCollectionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract partial class AbstractWritableArchive<TEntry, TVolume, TOptions>
|
||||
}
|
||||
var entry = CreateEntry(key, source, size, modified, closeStream);
|
||||
newEntries.Add(entry);
|
||||
await RebuildModifiedCollectionAsync();
|
||||
await RebuildModifiedCollectionAsync().ConfigureAwait(false);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,13 +152,15 @@ public abstract partial class AbstractWritableArchive<TEntry, TVolume, TOptions>
|
||||
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<IArchiveEntry> 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)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,8 @@ public static partial class ArchiveFactory
|
||||
)
|
||||
{
|
||||
readerOptions ??= ReaderOptions.ForExternalStream;
|
||||
var factory = await FindFactoryAsync<IArchiveFactory>(stream, cancellationToken);
|
||||
var factory = await FindFactoryAsync<IArchiveFactory>(stream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return factory.OpenAsyncArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
@@ -42,7 +43,8 @@ public static partial class ArchiveFactory
|
||||
{
|
||||
options ??= ReaderOptions.ForOwnedFile;
|
||||
|
||||
var factory = await FindFactoryAsync<IArchiveFactory>(fileInfo, cancellationToken);
|
||||
var factory = await FindFactoryAsync<IArchiveFactory>(fileInfo, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return factory.OpenAsyncArchive(fileInfo, options);
|
||||
}
|
||||
|
||||
@@ -62,13 +64,15 @@ public static partial class ArchiveFactory
|
||||
var fileInfo = filesArray[0];
|
||||
if (filesArray.Length == 1)
|
||||
{
|
||||
return await OpenAsyncArchive(fileInfo, options, cancellationToken);
|
||||
return await OpenAsyncArchive(fileInfo, options, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
options ??= ReaderOptions.ForOwnedFile;
|
||||
|
||||
var factory = await FindFactoryAsync<IMultiArchiveFactory>(fileInfo, cancellationToken);
|
||||
var factory = await FindFactoryAsync<IMultiArchiveFactory>(fileInfo, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return factory.OpenAsyncArchive(filesArray, options, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -89,13 +93,15 @@ public static partial class ArchiveFactory
|
||||
var firstStream = streamsArray[0];
|
||||
if (streamsArray.Length == 1)
|
||||
{
|
||||
return await OpenAsyncArchive(firstStream, options, cancellationToken);
|
||||
return await OpenAsyncArchive(firstStream, options, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
firstStream.NotNull(nameof(firstStream));
|
||||
options ??= ReaderOptions.ForExternalStream;
|
||||
|
||||
var factory = await FindFactoryAsync<IMultiArchiveFactory>(firstStream, cancellationToken);
|
||||
var factory = await FindFactoryAsync<IMultiArchiveFactory>(firstStream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return factory.OpenAsyncArchive(streamsArray, options);
|
||||
}
|
||||
|
||||
@@ -117,7 +123,7 @@ public static partial class ArchiveFactory
|
||||
{
|
||||
finfo.NotNull(nameof(finfo));
|
||||
using Stream stream = finfo.OpenRead();
|
||||
return await FindFactoryAsync<T>(stream, cancellationToken);
|
||||
return await FindFactoryAsync<T>(stream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async ValueTask<T> FindFactoryAsync<T>(
|
||||
@@ -140,7 +146,11 @@ public static partial class ArchiveFactory
|
||||
{
|
||||
stream.Seek(startPosition, SeekOrigin.Begin);
|
||||
|
||||
if (await factory.IsArchiveAsync(stream, cancellationToken: cancellationToken))
|
||||
if (
|
||||
await factory
|
||||
.IsArchiveAsync(stream, cancellationToken: cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
stream.Seek(startPosition, SeekOrigin.Begin);
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ public partial class GZipArchive
|
||||
{
|
||||
if (!entry.IsDirectory)
|
||||
{
|
||||
using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken);
|
||||
using var entryStream = await entry
|
||||
.OpenEntryStreamAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await writer
|
||||
.WriteAsync(
|
||||
entry.Key.NotNull("Entry Key is null"),
|
||||
@@ -62,7 +64,9 @@ public partial class GZipArchive
|
||||
}
|
||||
foreach (var entry in newEntries.Where(x => !x.IsDirectory))
|
||||
{
|
||||
using var entryStream = await entry.OpenEntryStreamAsync(cancellationToken);
|
||||
using var entryStream = await entry
|
||||
.OpenEntryStreamAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await writer
|
||||
.WriteAsync(entry.Key.NotNull("Entry Key is null"), entryStream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
@@ -80,10 +84,12 @@ public partial class GZipArchive
|
||||
IAsyncEnumerable<GZipVolume> 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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,11 +47,13 @@ public static class IArchiveEntryExtensions
|
||||
}
|
||||
|
||||
#if LEGACY_DOTNET
|
||||
using var entryStream = await archiveEntry.OpenEntryStreamAsync(cancellationToken);
|
||||
using var entryStream = await archiveEntry
|
||||
.OpenEntryStreamAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
#else
|
||||
await using var entryStream = await archiveEntry.OpenEntryStreamAsync(
|
||||
cancellationToken
|
||||
);
|
||||
await using var entryStream = await archiveEntry
|
||||
.OpenEntryStreamAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
#endif
|
||||
var sourceStream = WrapWithProgress(entryStream, archiveEntry, progress);
|
||||
await sourceStream
|
||||
|
||||
@@ -25,20 +25,27 @@ public static class IAsyncArchiveExtensions
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
if (await archive.IsSolidAsync() || archive.Type == ArchiveType.SevenZip)
|
||||
if (
|
||||
await archive.IsSolidAsync().ConfigureAwait(false)
|
||||
|| archive.Type == ArchiveType.SevenZip
|
||||
)
|
||||
{
|
||||
await using var reader = await archive.ExtractAllEntriesAsync();
|
||||
await using var reader = await archive
|
||||
.ExtractAllEntriesAsync()
|
||||
.ConfigureAwait(false);
|
||||
await reader
|
||||
.WriteAllToDirectoryAsync(destinationDirectory, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await archive.WriteToDirectoryAsyncInternal(
|
||||
destinationDirectory,
|
||||
progress,
|
||||
cancellationToken
|
||||
);
|
||||
await archive
|
||||
.WriteToDirectoryAsyncInternal(
|
||||
destinationDirectory,
|
||||
progress,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +55,7 @@ public static class IAsyncArchiveExtensions
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var totalBytes = await archive.TotalUncompressedSizeAsync();
|
||||
var totalBytes = await archive.TotalUncompressedSizeAsync().ConfigureAwait(false);
|
||||
var bytesRead = 0L;
|
||||
var seenDirectories = new HashSet<string>();
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ public partial class RarArchive
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
await base.DisposeAsync();
|
||||
await base.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async ValueTask<IAsyncReader> CreateReaderForSolidExtractionAsync()
|
||||
{
|
||||
if (await this.IsMultipartVolumeAsync())
|
||||
if (await this.IsMultipartVolumeAsync().ConfigureAwait(false))
|
||||
{
|
||||
var streams = await VolumesAsync
|
||||
.Select(volume =>
|
||||
@@ -39,15 +39,18 @@ public partial class RarArchive
|
||||
volume.Stream.Position = 0;
|
||||
return volume.Stream;
|
||||
})
|
||||
.ToListAsync();
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return (RarReader)RarReader.OpenReader(streams, ReaderOptions);
|
||||
}
|
||||
|
||||
var stream = (await VolumesAsync.FirstAsync()).Stream;
|
||||
var stream = (await VolumesAsync.FirstAsync().ConfigureAwait(false)).Stream;
|
||||
stream.Position = 0;
|
||||
return (RarReader)RarReader.OpenReader(stream, ReaderOptions);
|
||||
}
|
||||
|
||||
public override async ValueTask<bool> IsSolidAsync() =>
|
||||
await (await VolumesAsync.CastAsync<RarVolume>().FirstAsync()).IsSolidArchiveAsync();
|
||||
await (await VolumesAsync.CastAsync<RarVolume>().FirstAsync().ConfigureAwait(false))
|
||||
.IsSolidArchiveAsync()
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
/// </summary>
|
||||
public async ValueTask<bool> IsFirstVolumeAsync() =>
|
||||
(await archive.VolumesAsync.CastAsync<RarVolume>().FirstAsync()).IsFirstVolume;
|
||||
(
|
||||
await archive.VolumesAsync.CastAsync<RarVolume>().FirstAsync().ConfigureAwait(false)
|
||||
).IsFirstVolume;
|
||||
|
||||
/// <summary>
|
||||
/// RarArchive is part of a multi-part archive.
|
||||
/// </summary>
|
||||
public async ValueTask<bool> IsMultipartVolumeAsync() =>
|
||||
(await archive.VolumesAsync.CastAsync<RarVolume>().FirstAsync()).IsMultiVolume;
|
||||
(
|
||||
await archive.VolumesAsync.CastAsync<RarVolume>().FirstAsync().ConfigureAwait(false)
|
||||
).IsMultiVolume;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,12 @@ public partial class SevenZipArchive
|
||||
{
|
||||
stream.Position = 0;
|
||||
var reader = new ArchiveReader();
|
||||
await reader.OpenAsync(
|
||||
stream,
|
||||
lookForHeader: ReaderOptions.LookForHeader,
|
||||
cancellationToken
|
||||
);
|
||||
_database = await reader.ReadDatabaseAsync(
|
||||
new PasswordProvider(ReaderOptions.Password),
|
||||
cancellationToken
|
||||
);
|
||||
await reader
|
||||
.OpenAsync(stream, lookForHeader: ReaderOptions.LookForHeader, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
_database = await reader
|
||||
.ReadDatabaseAsync(new PasswordProvider(ReaderOptions.Password), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +34,8 @@ public partial class SevenZipArchive
|
||||
IAsyncEnumerable<SevenZipVolume> 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;
|
||||
|
||||
@@ -19,7 +19,10 @@ public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry
|
||||
|
||||
public async ValueTask<Stream> OpenEntryStreamAsync(
|
||||
CancellationToken cancellationToken = default
|
||||
) => (await FilePart.GetCompressedStreamAsync(cancellationToken)).NotNull();
|
||||
) =>
|
||||
(
|
||||
await FilePart.GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false)
|
||||
).NotNull();
|
||||
|
||||
public IArchive Archive { get; }
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public partial class TarArchive
|
||||
IAsyncEnumerable<TarVolume> volumes
|
||||
)
|
||||
{
|
||||
var stream = (await volumes.SingleAsync()).Stream;
|
||||
var stream = (await volumes.SingleAsync().ConfigureAwait(false)).Stream;
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
stream.Position = 0;
|
||||
@@ -136,7 +136,7 @@ public partial class TarArchive
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
await entryStream.CopyToAsync(memoryStream);
|
||||
await entryStream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||
memoryStream.Position = 0;
|
||||
var bytes = memoryStream.ToArray();
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ public partial class TarArchive
|
||||
#else
|
||||
using var reader = new AsyncBinaryReader(stream, leaveOpen: true);
|
||||
#endif
|
||||
var readSucceeded = await tarHeader.ReadAsync(reader);
|
||||
var readSucceeded = await tarHeader.ReadAsync(reader).ConfigureAwait(false);
|
||||
var isEmptyArchive =
|
||||
tarHeader.Name?.Length == 0
|
||||
&& tarHeader.Size == 0
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class ZipArchive
|
||||
IAsyncEnumerable<ZipVolume> volumes
|
||||
)
|
||||
{
|
||||
var vols = await volumes.ToListAsync();
|
||||
var vols = await volumes.ToListAsync().ConfigureAwait(false);
|
||||
var volsArray = vols.ToArray();
|
||||
|
||||
await foreach (
|
||||
|
||||
@@ -228,7 +228,8 @@ public partial class ZipArchive
|
||||
var header = await headerFactory
|
||||
.ReadStreamHeaderAsync(stream)
|
||||
.Where(x => x.ZipHeaderType != ZipHeaderType.Split)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
.FirstOrDefaultAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (header is null)
|
||||
{
|
||||
return false;
|
||||
@@ -271,6 +272,7 @@ public partial class ZipArchive
|
||||
await foreach (
|
||||
var h in z.ReadSeekableHeaderAsync(stream)
|
||||
.WithCancellation(cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
x = h;
|
||||
|
||||
@@ -15,7 +15,9 @@ public partial class ZipArchiveEntry
|
||||
var part = Parts.Single();
|
||||
if (part is SeekableZipFilePart seekablePart)
|
||||
{
|
||||
return (await seekablePart.GetCompressedStreamAsync(cancellationToken)).NotNull();
|
||||
return (
|
||||
await seekablePart.GetCompressedStreamAsync(cancellationToken).ConfigureAwait(false)
|
||||
).NotNull();
|
||||
}
|
||||
return OpenEntryStream();
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ internal sealed partial class GZipFilePart
|
||||
{
|
||||
var part = new GZipFilePart(stream, archiveEncoding);
|
||||
|
||||
await part.ReadAndValidateGzipHeaderAsync(cancellationToken);
|
||||
await part.ReadAndValidateGzipHeaderAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
var position = stream.Position;
|
||||
stream.Position = stream.Length - 8;
|
||||
await part.ReadTrailerAsync(cancellationToken);
|
||||
await part.ReadTrailerAsync(cancellationToken).ConfigureAwait(false);
|
||||
stream.Position = position;
|
||||
part.EntryStartPosition = position;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ internal sealed partial class GZipFilePart
|
||||
{
|
||||
// Read and potentially verify the GZIP trailer: CRC32 and size mod 2^32
|
||||
var trailer = new byte[8];
|
||||
_ = await _stream.ReadFullyAsync(trailer, 0, 8, cancellationToken);
|
||||
_ = await _stream.ReadFullyAsync(trailer, 0, 8, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Crc = BinaryPrimitives.ReadUInt32LittleEndian(trailer);
|
||||
UncompressedSize = BinaryPrimitives.ReadUInt32LittleEndian(trailer.AsSpan().Slice(4));
|
||||
@@ -53,7 +53,7 @@ internal sealed partial class GZipFilePart
|
||||
{
|
||||
// read the header on the first read
|
||||
var header = new byte[10];
|
||||
var n = await _stream.ReadAsync(header, 0, 10, cancellationToken);
|
||||
var n = await _stream.ReadAsync(header, 0, 10, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// workitem 8501: handle edge case (decompress empty stream)
|
||||
if (n == 0)
|
||||
@@ -77,28 +77,29 @@ internal sealed partial class GZipFilePart
|
||||
{
|
||||
// read and discard extra field
|
||||
var lengthField = new byte[2];
|
||||
_ = await _stream.ReadAsync(lengthField, 0, 2, cancellationToken);
|
||||
_ = await _stream.ReadAsync(lengthField, 0, 2, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var extraLength = (short)(lengthField[0] + (lengthField[1] * 256));
|
||||
var extra = new byte[extraLength];
|
||||
|
||||
if (!await _stream.ReadFullyAsync(extra, cancellationToken))
|
||||
if (!await _stream.ReadFullyAsync(extra, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
throw new ZlibException("Unexpected end-of-file reading GZIP header.");
|
||||
}
|
||||
}
|
||||
if ((header[3] & 0x08) == 0x08)
|
||||
{
|
||||
_name = await ReadZeroTerminatedStringAsync(_stream, cancellationToken);
|
||||
_name = await ReadZeroTerminatedStringAsync(_stream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
if ((header[3] & 0x10) == 0x010)
|
||||
{
|
||||
await ReadZeroTerminatedStringAsync(_stream, cancellationToken);
|
||||
await ReadZeroTerminatedStringAsync(_stream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
if ((header[3] & 0x02) == 0x02)
|
||||
{
|
||||
var buf = new byte[1];
|
||||
_ = await _stream.ReadAsync(buf, 0, 1, cancellationToken); // CRC16, ignore
|
||||
_ = await _stream.ReadAsync(buf, 0, 1, cancellationToken).ConfigureAwait(false); // CRC16, ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ internal sealed partial class GZipFilePart
|
||||
do
|
||||
{
|
||||
// workitem 7740
|
||||
var n = await stream.ReadAsync(buf1, 0, 1, cancellationToken);
|
||||
var n = await stream.ReadAsync(buf1, 0, 1, cancellationToken).ConfigureAwait(false);
|
||||
if (n != 1)
|
||||
{
|
||||
throw new ZlibException("Unexpected EOF reading GZIP header.");
|
||||
|
||||
@@ -57,47 +57,46 @@ internal class Rar5CryptoInfo
|
||||
)
|
||||
{
|
||||
var cryptoInfo = new Rar5CryptoInfo();
|
||||
var cryptVersion = await reader.ReadRarVIntUInt32Async(
|
||||
cancellationToken: CancellationToken.None
|
||||
);
|
||||
var cryptVersion = await reader
|
||||
.ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
if (cryptVersion > EncryptionConstV5.VERSION)
|
||||
{
|
||||
throw new CryptographicException($"Unsupported crypto version of {cryptVersion}");
|
||||
}
|
||||
var encryptionFlags = await reader.ReadRarVIntUInt32Async(
|
||||
cancellationToken: CancellationToken.None
|
||||
);
|
||||
var encryptionFlags = await reader
|
||||
.ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
cryptoInfo.UsePswCheck = FlagUtility.HasFlag(
|
||||
encryptionFlags,
|
||||
EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK
|
||||
);
|
||||
cryptoInfo.LG2Count = (int)
|
||||
await reader.ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None);
|
||||
await reader
|
||||
.ReadRarVIntUInt32Async(cancellationToken: CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
if (cryptoInfo.LG2Count > EncryptionConstV5.CRYPT5_KDF_LG2_COUNT_MAX)
|
||||
{
|
||||
throw new CryptographicException($"Unsupported LG2 count of {cryptoInfo.LG2Count}.");
|
||||
}
|
||||
|
||||
cryptoInfo.Salt = await reader.ReadBytesAsync(
|
||||
EncryptionConstV5.SIZE_SALT50,
|
||||
CancellationToken.None
|
||||
);
|
||||
cryptoInfo.Salt = await reader
|
||||
.ReadBytesAsync(EncryptionConstV5.SIZE_SALT50, CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (readInitV)
|
||||
{
|
||||
await cryptoInfo.ReadInitVAsync(reader);
|
||||
await cryptoInfo.ReadInitVAsync(reader).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (cryptoInfo.UsePswCheck)
|
||||
{
|
||||
cryptoInfo.PswCheck = await reader.ReadBytesAsync(
|
||||
EncryptionConstV5.SIZE_PSWCHECK,
|
||||
CancellationToken.None
|
||||
);
|
||||
var _pswCheckCsm = await reader.ReadBytesAsync(
|
||||
EncryptionConstV5.SIZE_PSWCHECK_CSUM,
|
||||
CancellationToken.None
|
||||
);
|
||||
cryptoInfo.PswCheck = await reader
|
||||
.ReadBytesAsync(EncryptionConstV5.SIZE_PSWCHECK, CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
var _pswCheckCsm = await reader
|
||||
.ReadBytesAsync(EncryptionConstV5.SIZE_PSWCHECK_CSUM, CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var sha = SHA256.Create();
|
||||
cryptoInfo.UsePswCheck = sha.ComputeHash(cryptoInfo.PswCheck)
|
||||
@@ -111,7 +110,9 @@ internal class Rar5CryptoInfo
|
||||
InitV = reader.ReadBytes(EncryptionConstV5.SIZE_INITV);
|
||||
|
||||
public async ValueTask ReadInitVAsync(AsyncMarkingBinaryReader reader) =>
|
||||
InitV = await reader.ReadBytesAsync(EncryptionConstV5.SIZE_INITV, CancellationToken.None);
|
||||
InitV = await reader
|
||||
.ReadBytesAsync(EncryptionConstV5.SIZE_INITV, CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
public bool UsePswCheck = false;
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ internal sealed partial class TarHeader
|
||||
|
||||
do
|
||||
{
|
||||
buffer = await ReadBlockAsync(reader);
|
||||
buffer = await ReadBlockAsync(reader).ConfigureAwait(false);
|
||||
|
||||
if (buffer.Length == 0)
|
||||
{
|
||||
@@ -216,12 +216,12 @@ internal sealed partial class TarHeader
|
||||
// to apply to the header that follows them.
|
||||
if (entryType == EntryType.LongName)
|
||||
{
|
||||
longName = await ReadLongNameAsync(reader, buffer);
|
||||
longName = await ReadLongNameAsync(reader, buffer).ConfigureAwait(false);
|
||||
continue;
|
||||
}
|
||||
else if (entryType == EntryType.LongLink)
|
||||
{
|
||||
longLinkName = await ReadLongNameAsync(reader, buffer);
|
||||
longLinkName = await ReadLongNameAsync(reader, buffer).ConfigureAwait(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ internal sealed partial class TarHeader
|
||||
var buffer = ArrayPool<byte>.Shared.Rent(BLOCK_SIZE);
|
||||
try
|
||||
{
|
||||
await reader.ReadBytesAsync(buffer, 0, BLOCK_SIZE);
|
||||
await reader.ReadBytesAsync(buffer, 0, BLOCK_SIZE).ConfigureAwait(false);
|
||||
|
||||
if (buffer.Length != 0 && buffer.Length < BLOCK_SIZE)
|
||||
{
|
||||
@@ -313,7 +313,7 @@ internal sealed partial class TarHeader
|
||||
var nameBytes = ArrayPool<byte>.Shared.Rent(nameLength);
|
||||
try
|
||||
{
|
||||
await reader.ReadBytesAsync(nameBytes, 0, nameLength);
|
||||
await reader.ReadBytesAsync(nameBytes, 0, nameLength).ConfigureAwait(false);
|
||||
var remainingBytesToRead = BLOCK_SIZE - (nameLength % BLOCK_SIZE);
|
||||
|
||||
// Read the rest of the block and discard the data
|
||||
@@ -322,7 +322,9 @@ internal sealed partial class TarHeader
|
||||
var remainingBytes = ArrayPool<byte>.Shared.Rent(remainingBytesToRead);
|
||||
try
|
||||
{
|
||||
await reader.ReadBytesAsync(remainingBytes, 0, remainingBytesToRead);
|
||||
await reader
|
||||
.ReadBytesAsync(remainingBytes, 0, remainingBytesToRead)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
using var reader = new AsyncBinaryReader(stream, leaveOpen: true);
|
||||
#endif
|
||||
|
||||
await SeekBackToHeaderAsync(stream, reader);
|
||||
await SeekBackToHeaderAsync(stream, reader).ConfigureAwait(false);
|
||||
|
||||
var eocd_location = stream.Position;
|
||||
var entry = new DirectoryEndHeader();
|
||||
await entry.Read(reader);
|
||||
await entry.Read(reader).ConfigureAwait(false);
|
||||
|
||||
if (entry.IsZip64)
|
||||
{
|
||||
@@ -30,24 +30,24 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
|
||||
// ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR should be before the EOCD
|
||||
stream.Seek(eocd_location - ZIP64_EOCD_LENGTH - 4, SeekOrigin.Begin);
|
||||
uint zip64_locator = await reader.ReadUInt32Async();
|
||||
uint zip64_locator = await reader.ReadUInt32Async().ConfigureAwait(false);
|
||||
if (zip64_locator != ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR)
|
||||
{
|
||||
throw new ArchiveException("Failed to locate the Zip64 Directory Locator");
|
||||
}
|
||||
|
||||
var zip64Locator = new Zip64DirectoryEndLocatorHeader();
|
||||
await zip64Locator.Read(reader);
|
||||
await zip64Locator.Read(reader).ConfigureAwait(false);
|
||||
|
||||
stream.Seek(zip64Locator.RelativeOffsetOfTheEndOfDirectoryRecord, SeekOrigin.Begin);
|
||||
var zip64Signature = await reader.ReadUInt32Async();
|
||||
var zip64Signature = await reader.ReadUInt32Async().ConfigureAwait(false);
|
||||
if (zip64Signature != ZIP64_END_OF_CENTRAL_DIRECTORY)
|
||||
{
|
||||
throw new ArchiveException("Failed to locate the Zip64 Header");
|
||||
}
|
||||
|
||||
var zip64Entry = new Zip64DirectoryEndHeader();
|
||||
await zip64Entry.Read(reader);
|
||||
await zip64Entry.Read(reader).ConfigureAwait(false);
|
||||
stream.Seek(zip64Entry.DirectoryStartOffsetRelativeToDisk, SeekOrigin.Begin);
|
||||
}
|
||||
else
|
||||
@@ -59,8 +59,8 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
while (true)
|
||||
{
|
||||
stream.Position = position;
|
||||
var signature = await reader.ReadUInt32Async();
|
||||
var nextHeader = await ReadHeader(signature, reader, _zip64);
|
||||
var signature = await reader.ReadUInt32Async().ConfigureAwait(false);
|
||||
var nextHeader = await ReadHeader(signature, reader, _zip64).ConfigureAwait(false);
|
||||
position = stream.Position;
|
||||
|
||||
if (nextHeader is null)
|
||||
@@ -101,7 +101,7 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
|
||||
try
|
||||
{
|
||||
await reader.ReadBytesAsync(seek, 0, len, default);
|
||||
await reader.ReadBytesAsync(seek, 0, len, default).ConfigureAwait(false);
|
||||
var memory = new Memory<byte>(seek, 0, len);
|
||||
var span = memory.Span;
|
||||
span.Reverse();
|
||||
@@ -137,8 +137,11 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
#else
|
||||
using var reader = new AsyncBinaryReader(stream, leaveOpen: true);
|
||||
#endif
|
||||
var signature = await reader.ReadUInt32Async();
|
||||
if (await ReadHeader(signature, reader, _zip64) is not LocalEntryHeader localEntryHeader)
|
||||
var signature = await reader.ReadUInt32Async().ConfigureAwait(false);
|
||||
if (
|
||||
await ReadHeader(signature, reader, _zip64).ConfigureAwait(false)
|
||||
is not LocalEntryHeader localEntryHeader
|
||||
)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
@@ -148,53 +148,63 @@ internal abstract partial class ZipFilePart
|
||||
}
|
||||
case ZipCompressionMethod.Reduce1:
|
||||
{
|
||||
return await ReduceStream.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
1,
|
||||
cancellationToken
|
||||
);
|
||||
return await ReduceStream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
1,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.Reduce2:
|
||||
{
|
||||
return await ReduceStream.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
2,
|
||||
cancellationToken
|
||||
);
|
||||
return await ReduceStream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
2,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.Reduce3:
|
||||
{
|
||||
return await ReduceStream.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
3,
|
||||
cancellationToken
|
||||
);
|
||||
return await ReduceStream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
3,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.Reduce4:
|
||||
{
|
||||
return await ReduceStream.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
4,
|
||||
cancellationToken
|
||||
);
|
||||
return await ReduceStream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
4,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.Explode:
|
||||
{
|
||||
return await ExplodeStream.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
Header.Flags,
|
||||
cancellationToken
|
||||
);
|
||||
return await ExplodeStream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
Header.CompressedSize,
|
||||
Header.UncompressedSize,
|
||||
Header.Flags,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
case ZipCompressionMethod.Deflate:
|
||||
@@ -207,12 +217,14 @@ internal abstract partial class ZipFilePart
|
||||
}
|
||||
case ZipCompressionMethod.BZip2:
|
||||
{
|
||||
return await BZip2Stream.CreateAsync(
|
||||
stream,
|
||||
CompressionMode.Decompress,
|
||||
false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
return await BZip2Stream
|
||||
.CreateAsync(
|
||||
stream,
|
||||
CompressionMode.Decompress,
|
||||
false,
|
||||
cancellationToken: cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.LZMA:
|
||||
{
|
||||
@@ -228,14 +240,16 @@ internal abstract partial class ZipFilePart
|
||||
await stream
|
||||
.ReadFullyAsync(props, 0, propsSize, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return await LzmaStream.CreateAsync(
|
||||
props,
|
||||
stream,
|
||||
Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1,
|
||||
FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1)
|
||||
? -1
|
||||
: Header.UncompressedSize
|
||||
);
|
||||
return await LzmaStream
|
||||
.CreateAsync(
|
||||
props,
|
||||
stream,
|
||||
Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1,
|
||||
FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1)
|
||||
? -1
|
||||
: Header.UncompressedSize
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
case ZipCompressionMethod.Xz:
|
||||
{
|
||||
|
||||
@@ -178,29 +178,34 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
var posState = (uint)outWindow.Total & _posStateMask;
|
||||
if (
|
||||
await _isMatchDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken) == 0
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 0
|
||||
)
|
||||
{
|
||||
byte b;
|
||||
var prevByte = outWindow.GetByte(0);
|
||||
if (!_state.IsCharState())
|
||||
{
|
||||
b = await _literalDecoder.DecodeWithMatchByteAsync(
|
||||
rangeDecoder,
|
||||
(uint)outWindow.Total,
|
||||
prevByte,
|
||||
outWindow.GetByte((int)_rep0),
|
||||
cancellationToken
|
||||
);
|
||||
b = await _literalDecoder
|
||||
.DecodeWithMatchByteAsync(
|
||||
rangeDecoder,
|
||||
(uint)outWindow.Total,
|
||||
prevByte,
|
||||
outWindow.GetByte((int)_rep0),
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
b = await _literalDecoder.DecodeNormalAsync(
|
||||
rangeDecoder,
|
||||
(uint)outWindow.Total,
|
||||
prevByte,
|
||||
cancellationToken
|
||||
);
|
||||
b = await _literalDecoder
|
||||
.DecodeNormalAsync(
|
||||
rangeDecoder,
|
||||
(uint)outWindow.Total,
|
||||
prevByte,
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
await outWindow.PutByteAsync(b, cancellationToken).ConfigureAwait(false);
|
||||
_state.UpdateChar();
|
||||
@@ -209,20 +214,23 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
uint len;
|
||||
if (
|
||||
await _isRepDecoders[_state._index].DecodeAsync(rangeDecoder, cancellationToken)
|
||||
== 1
|
||||
await _isRepDecoders[_state._index]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 1
|
||||
)
|
||||
{
|
||||
if (
|
||||
await _isRepG0Decoders[_state._index]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken) == 0
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 0
|
||||
)
|
||||
{
|
||||
if (
|
||||
await _isRep0LongDecoders[
|
||||
(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState
|
||||
]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken) == 0
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 0
|
||||
)
|
||||
{
|
||||
_state.UpdateShortRep();
|
||||
@@ -237,7 +245,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
uint distance;
|
||||
if (
|
||||
await _isRepG1Decoders[_state._index]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken) == 0
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 0
|
||||
)
|
||||
{
|
||||
distance = _rep1;
|
||||
@@ -246,7 +255,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
if (
|
||||
await _isRepG2Decoders[_state._index]
|
||||
.DecodeAsync(rangeDecoder, cancellationToken) == 0
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false) == 0
|
||||
)
|
||||
{
|
||||
distance = _rep2;
|
||||
@@ -339,6 +349,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
await _outWindow.TrainAsync(stream);
|
||||
await _outWindow.TrainAsync(stream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,14 +82,21 @@ public class TarFactory
|
||||
foreach (var wrapper in TarWrapper.Wrappers)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
if (await wrapper.IsMatchAsync(sharpCompressStream, cancellationToken))
|
||||
if (
|
||||
await wrapper
|
||||
.IsMatchAsync(sharpCompressStream, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
var decompressedStream = await wrapper.CreateStreamAsync(
|
||||
sharpCompressStream,
|
||||
cancellationToken
|
||||
);
|
||||
if (await TarArchive.IsTarFileAsync(decompressedStream, cancellationToken))
|
||||
var decompressedStream = await wrapper
|
||||
.CreateStreamAsync(sharpCompressStream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (
|
||||
await TarArchive
|
||||
.IsTarFileAsync(decompressedStream, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
return true;
|
||||
@@ -194,14 +201,21 @@ public class TarFactory
|
||||
foreach (var wrapper in TarWrapper.Wrappers)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
if (await wrapper.IsMatchAsync(sharpCompressStream, cancellationToken))
|
||||
if (
|
||||
await wrapper
|
||||
.IsMatchAsync(sharpCompressStream, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
var decompressedStream = await wrapper.CreateStreamAsync(
|
||||
sharpCompressStream,
|
||||
cancellationToken
|
||||
);
|
||||
if (await TarArchive.IsTarFileAsync(decompressedStream, cancellationToken))
|
||||
var decompressedStream = await wrapper
|
||||
.CreateStreamAsync(sharpCompressStream, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (
|
||||
await TarArchive
|
||||
.IsTarFileAsync(decompressedStream, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
sharpCompressStream.StopRecording();
|
||||
|
||||
@@ -82,7 +82,11 @@ public class ZipFactory
|
||||
var startPosition = stream.CanSeek ? stream.Position : -1;
|
||||
|
||||
// probe for single volume zip
|
||||
if (await ZipArchive.IsZipFileAsync(stream, password, cancellationToken))
|
||||
if (
|
||||
await ZipArchive
|
||||
.IsZipFileAsync(stream, password, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -96,7 +100,11 @@ public class ZipFactory
|
||||
stream.Position = startPosition;
|
||||
|
||||
//test the zip (last) file of a multipart zip
|
||||
if (await ZipArchive.IsZipMultiAsync(stream, password, cancellationToken))
|
||||
if (
|
||||
await ZipArchive
|
||||
.IsZipMultiAsync(stream, password, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ internal sealed class LazyAsyncReadOnlyCollection<T>(IAsyncEnumerable<T> source)
|
||||
}
|
||||
if (
|
||||
!lazyReadOnlyCollection._fullyLoaded
|
||||
&& await lazyReadOnlyCollection._source.MoveNextAsync()
|
||||
&& await lazyReadOnlyCollection._source.MoveNextAsync().ConfigureAwait(false)
|
||||
)
|
||||
{
|
||||
lazyReadOnlyCollection._backing.Add(lazyReadOnlyCollection._source.Current);
|
||||
@@ -76,7 +76,7 @@ internal sealed class LazyAsyncReadOnlyCollection<T>(IAsyncEnumerable<T> source)
|
||||
if (!_fullyLoaded)
|
||||
{
|
||||
var loader = new LazyLoader(this, CancellationToken.None);
|
||||
while (await loader.MoveNextAsync())
|
||||
while (await loader.MoveNextAsync().ConfigureAwait(false))
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ public abstract partial class AbstractReader<TEntry, TVolume>
|
||||
{
|
||||
if (_entriesForCurrentReadStreamAsync is not null)
|
||||
{
|
||||
await _entriesForCurrentReadStreamAsync.DisposeAsync();
|
||||
await _entriesForCurrentReadStreamAsync.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// If Volume implements IAsyncDisposable, use async disposal
|
||||
if (Volume is IAsyncDisposable asyncDisposable)
|
||||
{
|
||||
await asyncDisposable.DisposeAsync();
|
||||
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -43,14 +43,14 @@ public abstract partial class AbstractReader<TEntry, TVolume>
|
||||
}
|
||||
if (_entriesForCurrentReadStreamAsync is null)
|
||||
{
|
||||
return await LoadStreamForReadingAsync(RequestInitialStream());
|
||||
return await LoadStreamForReadingAsync(RequestInitialStream()).ConfigureAwait(false);
|
||||
}
|
||||
if (!_wroteCurrentEntry)
|
||||
{
|
||||
await SkipEntryAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
_wroteCurrentEntry = false;
|
||||
if (await NextEntryForCurrentStreamAsync(cancellationToken))
|
||||
if (await NextEntryForCurrentStreamAsync(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public abstract partial class AbstractReader<TEntry, TVolume>
|
||||
{
|
||||
if (_entriesForCurrentReadStreamAsync is not null)
|
||||
{
|
||||
await _entriesForCurrentReadStreamAsync.DisposeAsync();
|
||||
await _entriesForCurrentReadStreamAsync.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
if (stream is null || !stream.CanRead)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ public abstract partial class AbstractReader<TEntry, TVolume>
|
||||
);
|
||||
}
|
||||
_entriesForCurrentReadStreamAsync = GetEntriesAsync(stream).GetAsyncEnumerator();
|
||||
return await _entriesForCurrentReadStreamAsync.MoveNextAsync();
|
||||
return await _entriesForCurrentReadStreamAsync.MoveNextAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async ValueTask SkipEntryAsync(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user