From cf50311b9c39788e16c0ebe03aa02c73f2ee0f78 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 6 Jan 2026 12:45:13 +0000 Subject: [PATCH] Skip should use framework stuff --- src/SharpCompress/Utility.cs | 41 ++++++------------------------------ 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 6c627602..34325970 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -71,48 +71,19 @@ internal static class Utility return; } - using var buffer = MemoryPool.Shared.Rent(TEMP_BUFFER_SIZE); - while (advanceAmount > 0) - { - var toRead = (int)Math.Min(buffer.Memory.Length, advanceAmount); - var read = source.Read(buffer.Memory.Slice(0, toRead).Span); - if (read <= 0) - { - break; - } - advanceAmount -= read; - } + using var readOnlySubStream = new IO.ReadOnlySubStream(source, advanceAmount); + readOnlySubStream.CopyTo(Stream.Null); } - public static void Skip(this Stream source) - { - using var buffer = MemoryPool.Shared.Rent(TEMP_BUFFER_SIZE); - while (source.Read(buffer.Memory.Span) > 0) { } - } + public static void Skip(this Stream source) => source.CopyTo(Stream.Null); - public static async Task SkipAsync( + public static Task SkipAsync( this Stream source, CancellationToken cancellationToken = default ) { - var array = ArrayPool.Shared.Rent(TEMP_BUFFER_SIZE); - try - { - while (true) - { - var read = await source - .ReadAsync(array, 0, array.Length, cancellationToken) - .ConfigureAwait(false); - if (read <= 0) - { - break; - } - } - } - finally - { - ArrayPool.Shared.Return(array); - } + cancellationToken.ThrowIfCancellationRequested(); + return source.CopyToAsync(Stream.Null); } public static DateTime DosDateToDateTime(ushort iDate, ushort iTime)