Fix NotSupportedException in SharpCompressStream by checking CanSeek

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-23 14:38:11 +00:00
parent 32b1ec32c6
commit 253a46d458

View file

@ -57,11 +57,19 @@ public class SharpCompressStream : Stream, IStreamStack
{
ValidateBufferState(); // Add here
}
try
// Check CanSeek before accessing Position to avoid exception overhead
if (Stream.CanSeek)
{
_internalPosition = Stream.Position;
try
{
_internalPosition = Stream.Position;
}
catch
{
_internalPosition = 0;
}
}
catch
else
{
_internalPosition = 0;
}
@ -136,11 +144,19 @@ public class SharpCompressStream : Stream, IStreamStack
_readOnly = !Stream.CanSeek;
((IStreamStack)this).SetBuffer(bufferSize, forceBuffer);
try
// Check CanSeek before accessing Position to avoid exception overhead
if (stream.CanSeek)
{
_baseInitialPos = stream.Position;
try
{
_baseInitialPos = stream.Position;
}
catch
{
_baseInitialPos = 0;
}
}
catch
else
{
_baseInitialPos = 0;
}