Merge pull request #1402 from adamhathcock/adam/parallel-lzma-fixes

Fixes for parallel lzma usage
This commit is contained in:
Adam Hathcock
2026-08-04 10:22:29 +01:00
committed by GitHub
5 changed files with 19 additions and 47 deletions

View File

@@ -71,12 +71,16 @@ public static partial class IArchiveEntryExtensions
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);

View File

@@ -30,18 +30,7 @@ public partial class EntryStream : AsyncDisposableStream
_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

View File

@@ -29,18 +29,7 @@ internal class TarReadOnlySubStream : Stream
_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);
}

View File

@@ -69,28 +69,27 @@ internal partial class WinzipAesCryptoStream : Stream
_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);

View File

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