mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 23:45:14 +00:00
more
This commit is contained in:
@@ -21,7 +21,7 @@ public abstract partial class ArjHeader
|
||||
{
|
||||
// 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<byte>();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public abstract partial class ArjHeader
|
||||
|
||||
// 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 abstract partial class ArjHeader
|
||||
}
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
byte[] crc = new byte[4];
|
||||
read = await stream.ReadAsync(crc, 0, 4, cancellationToken);
|
||||
read = await stream.ReadAsync(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 @@ public abstract partial class ArjHeader
|
||||
|
||||
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 @@ public abstract partial class ArjHeader
|
||||
}
|
||||
|
||||
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 @@ public abstract partial class ArjHeader
|
||||
}
|
||||
|
||||
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 abstract partial class ArjHeader
|
||||
)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -64,19 +64,19 @@ public partial class RarHeaderFactory
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ internal sealed partial class ArchiveReader
|
||||
{
|
||||
// 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 @@ internal sealed partial class ArchiveReader
|
||||
_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)
|
||||
{
|
||||
|
||||
@@ -298,11 +298,12 @@ internal abstract partial class ZipFilePart
|
||||
}
|
||||
|
||||
return await CreateDecompressionStreamAsync(
|
||||
stream,
|
||||
(ZipCompressionMethod)
|
||||
BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)),
|
||||
cancellationToken
|
||||
);
|
||||
stream,
|
||||
(ZipCompressionMethod)
|
||||
BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)),
|
||||
cancellationToken
|
||||
)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -818,7 +818,7 @@ internal partial class CBZip2InputStream
|
||||
var b = ArrayPool<byte>.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 +844,15 @@ internal partial class CBZip2InputStream
|
||||
}
|
||||
|
||||
private async ValueTask<char> BsGetUCharAsync(CancellationToken cancellationToken) =>
|
||||
(char)await BsRAsync(8, cancellationToken);
|
||||
(char)await BsRAsync(8, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
private async ValueTask<int> BsGetIntVSAsync(
|
||||
int numBits,
|
||||
CancellationToken cancellationToken
|
||||
) => await BsRAsync(numBits, cancellationToken);
|
||||
) => await BsRAsync(numBits, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
private async ValueTask<int> BsGetInt32Async(CancellationToken cancellationToken) =>
|
||||
await BsGetintAsync(cancellationToken);
|
||||
await BsGetintAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
public static async ValueTask<CBZip2InputStream> CreateAsync(
|
||||
Stream zStream,
|
||||
@@ -864,10 +864,10 @@ internal partial class CBZip2InputStream
|
||||
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);
|
||||
await cbZip2InputStream.BsSetStreamAsync(zStream, cancellationToken).ConfigureAwait(false);
|
||||
await cbZip2InputStream.InitializeAsync(true, cancellationToken).ConfigureAwait(false);
|
||||
await cbZip2InputStream.InitBlockAsync(cancellationToken).ConfigureAwait(false);
|
||||
await cbZip2InputStream.SetupBlockAsync(cancellationToken).ConfigureAwait(false);
|
||||
return cbZip2InputStream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,16 +47,16 @@ public partial class LzmaStream
|
||||
{
|
||||
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 @@ public partial class LzmaStream
|
||||
_decoder.SetDecoderProperties(Properties);
|
||||
}
|
||||
|
||||
await _rangeDecoder.InitAsync(_inputStream, cancellationToken);
|
||||
await _rangeDecoder.InitAsync(_inputStream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else if (control > 0x02)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
)
|
||||
{
|
||||
var stream = new MultiVolumeReadOnlyAsyncStream(parts);
|
||||
await stream.filePartEnumerator.MoveNextAsync();
|
||||
await stream.filePartEnumerator.MoveNextAsync().ConfigureAwait(false);
|
||||
stream.InitializeNextFilePart();
|
||||
return stream;
|
||||
}
|
||||
@@ -23,10 +23,10 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
#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 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
}
|
||||
|
||||
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 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
);
|
||||
}
|
||||
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: "
|
||||
|
||||
@@ -47,7 +47,7 @@ public static class AsyncEnumerableExtensions
|
||||
await using var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
|
||||
var count = 0;
|
||||
while (await e.MoveNextAsync())
|
||||
while (await e.MoveNextAsync().ConfigureAwait(false))
|
||||
{
|
||||
checked
|
||||
{
|
||||
@@ -117,12 +117,12 @@ public static class AsyncEnumerableExtensions
|
||||
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."
|
||||
|
||||
@@ -73,19 +73,16 @@ public static partial class ReaderFactory
|
||||
{
|
||||
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 @@ public static partial class ReaderFactory
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user