fix SharpCompressStream BufferSize setter and Seek as well

the BufferSize setter was completely broken and trashed the `_internalPosition` value on set, for `Seek` this is just an off-by-one fix allowing seeking to immediately past the last byte in the buffer
This commit is contained in:
Morilli
2025-11-14 01:49:01 +01:00
parent 9a876abd31
commit 783521928d

View File

@@ -79,7 +79,7 @@ public class SharpCompressStream : Stream, IStreamStack
{
if (value < 0 || value > _bufferedLength)
throw new ArgumentOutOfRangeException(nameof(value));
_internalPosition = value;
_internalPosition = _internalPosition - _bufferPosition + value;
_bufferPosition = value;
ValidateBufferState(); // Add here
}
@@ -291,7 +291,7 @@ public class SharpCompressStream : Stream, IStreamStack
long bufferPos = _internalPosition - _bufferPosition;
if (targetPos >= bufferPos && targetPos < bufferPos + _bufferedLength)
if (targetPos >= bufferPos && targetPos <= bufferPos + _bufferedLength)
{
_bufferPosition = (int)(targetPos - bufferPos); //repoint within the buffer
_internalPosition = targetPos;