mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1084] [MERGED] Avoid NotSupportedException overhead in SharpCompressStream for non-seekable streams #1506
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/adamhathcock/sharpcompress/pull/1084
Author: @Copilot
Created: 12/23/2025
Status: ✅ Merged
Merged: 12/23/2025
Merged by: @adamhathcock
Base:
master← Head:copilot/fix-handled-system-exception📝 Commits (5)
32b1ec3Initial plan253a46dFix NotSupportedException in SharpCompressStream by checking CanSeekd614bebAdd explanatory comments for CanSeek checks and try-catch blocks6991900Remove try/catch blocks, just check CanSeek as requested4dbe0b9Update src/SharpCompress/IO/SharpCompressStream.cs📊 Changes
1 file changed (+4 additions, -16 deletions)
View changed files
📝
src/SharpCompress/IO/SharpCompressStream.cs(+4 -16)📄 Description
SharpCompressStreamwas attempting to accessstream.Positionwithout checkingCanSeek, causingNotSupportedExceptionto be thrown and caught for every non-seekable stream (e.g., XZ'sReadOnlyStream). This exception overhead occurred in the constructor and buffer allocation, impacting performance for formats using non-seekable streams.Changes
stream.CanSeekbefore accessingPositionin two locations:_baseInitialPosBufferSizesetter initialization of_internalPositionImpact
Eliminates exception overhead for non-seekable streams while maintaining identical behavior for seekable streams. No API changes.
<issue_title>Handled System.NotSupportedException but can be avoided?</issue_title>
><issue_description>Open xz file like this:
>
> using var fileStream = new FileStream(updateFilename, FileMode.Open, FileAccess.Read);
> using var reader = ReaderFactory.Open(fileStream, new SharpCompress.Readers.ReaderOptions()
> {
> LeaveStreamOpen = true,
> });
>
>
>
SharpCompressStreamis wrapped aroundReadOnlyStreamandReadOnlyStreamdoesnt' support Position get. InSharpCompressStreamexception is handled:>
> try
> {
> _baseInitialPos = stream.Position;
> }
> catch
> {
> _baseInitialPos = 0;
> }
>
> But this is still exception thrown for each entry I think which causes performance issues. Can it be avoided? Check for
CanSeek?</issue_description>>
> ## Comments on the Issue (you are @copilot in this section)
>
>
>
>
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.