mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #945] Extension hinting for ReaderFactory for better first try factory success #1363
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/945
State: closed
Merged: Yes
Also used by TarFactory to hint what compressiontype to attempt first
Close #942
This adds extension hinting support to ReaderFactory and allows compressors to optionally use the hinting as well for their own prioritization.
This only prioritizes which factories/methods we try first so should not result in a change of functionality for anyone (it also only does the prioritization if you provide the extension as a hint).
I added prioritization to tar as well, this required rewriting it a bit but it allowed removing a good bit of duplicate code. I don't know why certain tar methods require wrapping the rewind stream again, would seem this maybe should be a property on the type, but I did preserve this functionality.
I added gzip to TarFactory as well. While the GzipFactory would eventually handle it from brute force it seemed like it belonged in TarFactory with the others.
For bare tar archives I no longer use TarReader.Open as it has redundant code once again brute forcing the compression types. Given the code path was only triggered if the IsTarFile check passed before even if they were slightly different it shouldn't matter.
I don't think this introduces much of a different code path that could be exploited but the tar change would probably be the biggest.
This makes it a bit easier to track 'legitimate' exceptions in the library when debugging vs ones caused during the type brute forcing.