From 934b86c79f3e21bee1d7c853997bad820e4e6fc3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 8 Oct 2023 16:48:56 +0100 Subject: [PATCH] [OffsetStream] Do not raise an exception if trying to read past stream end, just return partial data. --- IO/OffsetStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IO/OffsetStream.cs b/IO/OffsetStream.cs index 809b894..07fa54a 100644 --- a/IO/OffsetStream.cs +++ b/IO/OffsetStream.cs @@ -595,7 +595,7 @@ public sealed class OffsetStream : Stream public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if(_baseStream.Position + count > _streamEnd) - throw new IOException(Localization.Cannot_read_past_stream_end); + count = (int)(_streamEnd - _baseStream.Position); return _baseStream.BeginRead(buffer, offset, count, callback, state); } @@ -637,7 +637,7 @@ public sealed class OffsetStream : Stream public override int Read(byte[] buffer, int offset, int count) { if(_baseStream.Position + count > _streamEnd + 1) - throw new IOException(Localization.Cannot_read_past_stream_end); + count = (int)(_streamEnd - _baseStream.Position); return _baseStream.EnsureRead(buffer, offset, count); }