Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Flush on EntryStream #417

Merged
merged 3 commits into from
Oct 4, 2018

Conversation

KyotoFox
Copy link
Contributor

@KyotoFox KyotoFox commented Oct 4, 2018

I have a tar-file that contains another tar.gz-file that I want do extract using SharpCompress.
When I am iterating through the outer tar-file, and find the tar.gz-file I want to extract, I use a CryptoStream that calculates the SHA256-sum of the tar.gz-entry while I extract it (using the IReader extension WriteAllToDirectory)

This seems to work without issues, but somtimes (due to CryptoStreams internal implementation), the tar.gz EntryStream will throw a NotSupportedException when the CryptoStream is being Disposed, because it will sometimes call Flush() on the EntryStream (see here).

From what I can see there is no reason to not allow flushing the EntryStream, as there is nothing to flush. Microsoft also mentions in the Stream.Flush-documentation that read-only streams should implement Flush with an empty method.
This pull request fixes that, and also adds a test that "provokes" this issue (not sure if that is needed or wanted)

From Microsoft docs: “In a class derived from Stream that doesn't
support writing, Flush is typically implemented as an empty method to
ensure full compatibility with other Stream types since it's valid to
flush a read-only stream.”
@adamhathcock
Copy link
Owner

You're right. I think there's no reason to throw an exception on Flush. Empty implementation is harmless. This is perfect. Thank you!

@adamhathcock adamhathcock merged commit 0941239 into adamhathcock:master Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants