Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/SharpCompress/Archives/AbstractArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected virtual async IAsyncEnumerable<TEntry> LoadEntriesAsync(
IAsyncEnumerable<TVolume> volumes
)
{
foreach (var item in LoadEntries(await volumes.ToListAsync()))
foreach (var item in LoadEntries(await volumes.ToListAsync().ConfigureAwait(false)))
{
yield return item;
}
Expand All @@ -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<IArchiveEntry> EntriesAsyncCast()
Expand All @@ -73,29 +73,31 @@ private async IAsyncEnumerable<IVolume> VolumesAsyncCast()

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);

Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/Archives/AbstractWritableArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async ValueTask RemoveEntryAsync(TEntry entry)
if (!removedEntries.Contains(entry))
{
removedEntries.Add(entry);
await RebuildModifiedCollectionAsync();
await RebuildModifiedCollectionAsync().ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public async ValueTask<TEntry> AddEntryAsync(
}
var entry = CreateEntry(key, source, size, modified, closeStream);
newEntries.Add(entry);
await RebuildModifiedCollectionAsync();
await RebuildModifiedCollectionAsync().ConfigureAwait(false);
return entry;
}

Expand All @@ -106,7 +106,7 @@ public async ValueTask<TEntry> AddDirectoryEntryAsync(
}
var entry = CreateDirectoryEntry(key, modified);
newEntries.Add(entry);
await RebuildModifiedCollectionAsync();
await RebuildModifiedCollectionAsync().ConfigureAwait(false);
return entry;
}

Expand Down
6 changes: 4 additions & 2 deletions src/SharpCompress/Archives/AbstractWritableArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ async ValueTask<IArchiveEntry> 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<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)
{
Expand Down
26 changes: 18 additions & 8 deletions src/SharpCompress/Archives/ArchiveFactory.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static async ValueTask<IAsyncArchive> OpenAsyncArchive(
)
{
readerOptions ??= ReaderOptions.ForExternalStream;
var factory = await FindFactoryAsync<IArchiveFactory>(stream, cancellationToken);
var factory = await FindFactoryAsync<IArchiveFactory>(stream, cancellationToken)
.ConfigureAwait(false);
return factory.OpenAsyncArchive(stream, readerOptions);
}

Expand All @@ -42,7 +43,8 @@ public static async ValueTask<IAsyncArchive> OpenAsyncArchive(
{
options ??= ReaderOptions.ForOwnedFile;

var factory = await FindFactoryAsync<IArchiveFactory>(fileInfo, cancellationToken);
var factory = await FindFactoryAsync<IArchiveFactory>(fileInfo, cancellationToken)
.ConfigureAwait(false);
return factory.OpenAsyncArchive(fileInfo, options);
}

Expand All @@ -62,13 +64,15 @@ public static async ValueTask<IAsyncArchive> 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<IMultiArchiveFactory>(fileInfo, cancellationToken);
var factory = await FindFactoryAsync<IMultiArchiveFactory>(fileInfo, cancellationToken)
.ConfigureAwait(false);
return factory.OpenAsyncArchive(filesArray, options);
}

Expand All @@ -89,13 +93,15 @@ public static async ValueTask<IAsyncArchive> 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<IMultiArchiveFactory>(firstStream, cancellationToken);
var factory = await FindFactoryAsync<IMultiArchiveFactory>(firstStream, cancellationToken)
.ConfigureAwait(false);
return factory.OpenAsyncArchive(streamsArray, options);
}

Expand All @@ -117,7 +123,7 @@ CancellationToken cancellationToken
{
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>(
Expand All @@ -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);

Expand Down
14 changes: 10 additions & 4 deletions src/SharpCompress/Archives/GZip/GZipArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
Expand All @@ -80,10 +84,12 @@ protected override async IAsyncEnumerable<GZipArchiveEntry> LoadEntriesAsync(
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
);
}
Expand Down
10 changes: 6 additions & 4 deletions src/SharpCompress/Archives/IArchiveEntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions src/SharpCompress/Archives/IAsyncArchiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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<string>();

Expand Down
16 changes: 9 additions & 7 deletions src/SharpCompress/Archives/IWritableAsyncArchiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/SharpCompress/Archives/Rar/RarArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@ public override async ValueTask DisposeAsync()
}

_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 =>
{
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);
}
8 changes: 6 additions & 2 deletions src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
14 changes: 7 additions & 7 deletions src/SharpCompress/Archives/Rar/RarArchiveEntry.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public async ValueTask<Stream> OpenEntryStreamAsync(
stream = new RarStream(
archive.UnpackV1.Value,
FileHeader,
await MultiVolumeReadOnlyAsyncStream.Create(
Parts.ToAsyncEnumerable().CastAsync<RarFilePart>()
)
await MultiVolumeReadOnlyAsyncStream
.Create(Parts.ToAsyncEnumerable().CastAsync<RarFilePart>())
.ConfigureAwait(false)
);
}
else
{
stream = new RarStream(
archive.UnpackV2017.Value,
FileHeader,
await MultiVolumeReadOnlyAsyncStream.Create(
Parts.ToAsyncEnumerable().CastAsync<RarFilePart>()
)
await MultiVolumeReadOnlyAsyncStream
.Create(Parts.ToAsyncEnumerable().CastAsync<RarFilePart>())
.ConfigureAwait(false)
);
}

await stream.InitializeAsync(cancellationToken);
await stream.InitializeAsync(cancellationToken).ConfigureAwait(false);
return stream;
}
}
Loading