mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 07:25:11 +00:00
Remove try/catch blocks, just check CanSeek as requested
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
@@ -58,23 +58,7 @@ public class SharpCompressStream : Stream, IStreamStack
|
||||
ValidateBufferState(); // Add here
|
||||
}
|
||||
// Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams.
|
||||
// Keep try-catch as defensive programming since some streams may report CanSeek=true
|
||||
// but still throw on Position access in certain edge cases.
|
||||
if (Stream.CanSeek)
|
||||
{
|
||||
try
|
||||
{
|
||||
_internalPosition = Stream.Position;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_internalPosition = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_internalPosition = 0;
|
||||
}
|
||||
_internalPosition = Stream.CanSeek ? Stream.Position : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,23 +131,7 @@ public class SharpCompressStream : Stream, IStreamStack
|
||||
|
||||
((IStreamStack)this).SetBuffer(bufferSize, forceBuffer);
|
||||
// Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams.
|
||||
// Keep try-catch as defensive programming since some streams may report CanSeek=true
|
||||
// but still throw on Position access in certain edge cases.
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
try
|
||||
{
|
||||
_baseInitialPos = stream.Position;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_baseInitialPos = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_baseInitialPos = 0;
|
||||
}
|
||||
_baseInitialPos = stream.CanSeek ? stream.Position : 0;
|
||||
|
||||
#if DEBUG_STREAMS
|
||||
this.DebugConstruct(typeof(SharpCompressStream));
|
||||
|
||||
Reference in New Issue
Block a user