From 6991900eb0f398c940d54856bd554ae85350e774 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 15:01:41 +0000 Subject: [PATCH] Remove try/catch blocks, just check CanSeek as requested Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- src/SharpCompress/IO/SharpCompressStream.cs | 36 ++------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index 0ec15136..131ea49c 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -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));