From f982fa3abed817de66ec4dc29bf7507301ceb890 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 28 May 2026 07:27:23 +0100 Subject: [PATCH] use ValueTask overload when possible --- src/SharpCompress/Utility.Async.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SharpCompress/Utility.Async.cs b/src/SharpCompress/Utility.Async.cs index f717eb31..1c11ccc6 100644 --- a/src/SharpCompress/Utility.Async.cs +++ b/src/SharpCompress/Utility.Async.cs @@ -43,9 +43,15 @@ internal static partial class Utility while (length > 0) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + var fetched = await source + .ReadAsync(buffer.AsMemory(offset, length), cancellationToken) + .ConfigureAwait(false); +#else var fetched = await source .ReadAsync(buffer, offset, length, cancellationToken) .ConfigureAwait(false); +#endif if (fetched <= 0) { throw new IncompleteArchiveException("Unexpected end of stream."); @@ -79,9 +85,15 @@ internal static partial class Utility int read; while ( ( +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + read = await source + .ReadAsync(buffer.AsMemory(total, buffer.Length - total), cancellationToken) + .ConfigureAwait(false) +#else read = await source .ReadAsync(buffer, total, buffer.Length - total, cancellationToken) .ConfigureAwait(false) +#endif ) > 0 ) { @@ -105,9 +117,18 @@ internal static partial class Utility int read; while ( ( +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + read = await source + .ReadAsync( + buffer.AsMemory(offset + total, count - total), + cancellationToken + ) + .ConfigureAwait(false) +#else read = await source .ReadAsync(buffer, offset + total, count - total, cancellationToken) .ConfigureAwait(false) +#endif ) > 0 ) {