Merge pull request #1084 from adamhathcock/copilot/fix-handled-system-exception

Avoid NotSupportedException overhead in SharpCompressStream for non-seekable streams
This commit is contained in:
Adam Hathcock
2025-12-23 15:15:15 +00:00
committed by GitHub

View File

@@ -57,14 +57,8 @@ public class SharpCompressStream : Stream, IStreamStack
{
ValidateBufferState(); // Add here
}
try
{
_internalPosition = Stream.Position;
}
catch
{
_internalPosition = 0;
}
// Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams.
_internalPosition = Stream.CanSeek ? Stream.Position : 0;
}
}
}
@@ -136,14 +130,8 @@ public class SharpCompressStream : Stream, IStreamStack
_readOnly = !Stream.CanSeek;
((IStreamStack)this).SetBuffer(bufferSize, forceBuffer);
try
{
_baseInitialPos = stream.Position;
}
catch
{
_baseInitialPos = 0;
}
// Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams.
_baseInitialPos = Stream.CanSeek ? Stream.Position : 0;
#if DEBUG_STREAMS
this.DebugConstruct(typeof(SharpCompressStream));