mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1151] Fix EntryStream.Dispose() throwing NotSupportedException on non-seekable streams #1591
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?
Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1151
State: closed
Merged: Yes
Fix EntryStream.Dispose() NotSupportedException on non-seekable streams
Problem
Since version 0.41.0,
EntryStream.Dispose()callsFlush()on DeflateStream and LzmaStream to handle over-read issues. However, this causesNotSupportedExceptionin legitimate streaming scenarios with non-seekable streams (e.g., ASP.NET Core HttpRequest.Body).Solution
Wrapped the
Flush()andFlushAsync()calls in try-catch blocks that safely ignoreNotSupportedException. This maintains the over-read correction behavior for streams that support it, while gracefully degrading for non-seekable streams.Plan
Changes Made
EntryStream.Dispose()to wrapFlush()calls in try-catch blocksEntryStream.DisposeAsync()to wrapFlushAsync()calls in try-catch blocksNotSupportedExceptionfrom Flush operationsEntryStream_Dispose_DoesNotThrow_OnNonSeekableStream_DeflateandEntryStream_Dispose_DoesNotThrow_OnNonSeekableStream_LZMAEntryStream_Dispose_DoesNotThrow_OnNonSeekableStream_Deflate_AsyncandEntryStream_Dispose_DoesNotThrow_OnNonSeekableStream_LZMA_AsyncTest Results
Security Summary
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.