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
4 changes: 4 additions & 0 deletions src/SharpCompress/Archives/IArchiveEntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ private async ValueTask WriteToAsync(
throw new ExtractionException("Entry is a file directory and cannot be extracted.");
}

#if SYNC_ONLY
using var entryStream = archiveEntry.OpenEntryStream();
#else
var entryStream = await archiveEntry
.OpenEntryStreamAsync(cancellationToken)
.ConfigureAwait(false);
await using var entryStreamScope = entryStream
.DisposeAsyncScope()
.ConfigureAwait(false);
#endif
var checkedStream = options is null
? entryStream
: IEntryExtensions.WrapWithChecksumValidation(archiveEntry, entryStream, options);
Expand Down
13 changes: 1 addition & 12 deletions src/SharpCompress/Common/EntryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ protected override void Dispose(bool disposing)
_isDisposed = true;
if (!(_completed || _reader.Cancelled))
{
if (Utility.UseSyncOverAsyncDispose())
{
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
#pragma warning disable CA2012
SkipEntryAsync().GetAwaiter().GetResult();
#pragma warning restore CA2012
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
}
else
{
SkipEntry();
}
SkipEntry();
}

//Need a safe standard approach to this - it's okay for compression to overreads. Handling needs to be standardised
Expand Down
13 changes: 1 addition & 12 deletions src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ protected override void Dispose(bool disposing)
_isDisposed = true;
if (disposing)
{
if (Utility.UseSyncOverAsyncDispose())
{
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
#pragma warning disable CA2012
AdvanceToNextHeaderAsync().GetAwaiter().GetResult();
#pragma warning restore CA2012
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
}
else
{
AdvanceToNextHeader();
}
AdvanceToNextHeader();
}
base.Dispose(disposing);
}
Expand Down
27 changes: 13 additions & 14 deletions src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,27 @@ protected override void Dispose(bool disposing)
_isDisposed = true;
if (disposing)
{
// Read out last 10 auth bytes - catch exceptions for async-only streams
if (Utility.UseSyncOverAsyncDispose())
// Read out last 10 auth bytes
#if LEGACY_DOTNET
// Stream has no DisposeAsync on legacy targets, so async flows fall back to this
// sync Dispose while the underlying stream may be async-only.
var ten = ArrayPool<byte>.Shared.Rent(10);
try
{
var ten = ArrayPool<byte>.Shared.Rent(10);
try
{
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
#pragma warning disable CA2012
_stream.ReadFullyAsync(ten, 0, 10).GetAwaiter().GetResult();
_stream.ReadFullyAsync(ten, 0, 10).GetAwaiter().GetResult();
#pragma warning restore CA2012
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
}
finally
{
ArrayPool<byte>.Shared.Return(ten);
}
}
else
finally
{
Span<byte> ten = stackalloc byte[10];
_stream.ReadFully(ten);
ArrayPool<byte>.Shared.Return(ten);
}
#else
Span<byte> ten = stackalloc byte[10];
_stream.ReadFully(ten);
#endif
_stream.Dispose();
}
base.Dispose(disposing);
Expand Down
9 changes: 0 additions & 9 deletions src/SharpCompress/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ internal static partial class Utility
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;

public static bool UseSyncOverAsyncDispose()
{
var useSyncOverAsync = false;
#if LEGACY_DOTNET
useSyncOverAsync = true;
#endif
return useSyncOverAsync;
}

private static readonly HashSet<char> invalidChars = new(Path.GetInvalidFileNameChars());

public static ReadOnlyCollection<T> ToReadOnly<T>(this IList<T> items) => new(items);
Expand Down