mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #400] [MERGED] Avoid throwing NotSupportedException in ReaderFactory hot path #1005
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/400
Author: @MattKotsenas
Created: 7/10/2018
Status: ✅ Merged
Merged: 7/10/2018
Merged by: @adamhathcock
Base:
master← Head:feature/avoid-exception-in-readerfactory📝 Commits (1)
bebccaaAvoid throwingNotSupportedExceptioninReaderFactoryhot path📊 Changes
2 files changed (+2 additions, -1 deletions)
View changed files
📝
src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs(+1 -0)📝
src/SharpCompress/Common/Zip/ZipHeaderFactory.cs(+1 -1)📄 Description
ReaderFactory.Open()callsZipArchive.IsZipFile()to determine if the stream is a zip archive, which calls intoZipHeaderFactory.ReadHeader(), which throws aNotSupportedExceptionwhen the bytes do not match a valid header.To be clear, this exception is caught and
IsZipFile()returnsfalse, but when called in a hot-path, these exceptions can become expensive.To address this issue,
ReadHeadernow returnsnullin the default cause instead of throwing. All callsites were already checking for and handlingnull, so no behavior should change.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.