diff --git a/src/SharpCompress/IO/ReadOnlySubStream.cs b/src/SharpCompress/IO/ReadOnlySubStream.cs index 7b39a45b..fb576c09 100644 --- a/src/SharpCompress/IO/ReadOnlySubStream.cs +++ b/src/SharpCompress/IO/ReadOnlySubStream.cs @@ -34,12 +34,37 @@ namespace SharpCompress.IO public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + { + var count = buffer.Length; + if (BytesLeftToRead < count) + { + count = (int)BytesLeftToRead; + } + + if (count == 0) + { + return 0; + } + int read = await Stream.ReadAsync(buffer.Slice(0, count), cancellationToken); + if (read > 0) + { + BytesLeftToRead -= read; + } + return read; + } + public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (BytesLeftToRead < count) { count = (int)BytesLeftToRead; } + + if (count == 0) + { + return 0; + } int read = await Stream.ReadAsync(buffer, offset, count, cancellationToken); if (read > 0) {