[PR #417] [MERGED] Allow Flush on EntryStream #1017

Open
opened 2026-01-29 22:18:37 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/417
Author: @KyotoFox
Created: 10/4/2018
Status: Merged
Merged: 10/4/2018
Merged by: @adamhathcock

Base: masterHead: fix-entrystream-flush


📝 Commits (3)

  • efae832 Don't throw an exception when flushing an EntryStream
  • 6dd5da4 Added test that calls EntryStream.Flush()
  • 53ad00c Use soft tabs

📊 Changes

4 files changed (+84 additions, -3 deletions)

View changed files

📝 src/SharpCompress/Common/EntryStream.cs (+1 -3)
tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs (+57 -0)
📝 tests/SharpCompress.Test/Tar/TarReaderTests.cs (+26 -0)
tests/TestArchives/Archives/Tar.ContainsTarGz.tar (+0 -0)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/417 **Author:** [@KyotoFox](https://github.com/KyotoFox) **Created:** 10/4/2018 **Status:** ✅ Merged **Merged:** 10/4/2018 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `fix-entrystream-flush` --- ### 📝 Commits (3) - [`efae832`](https://github.com/adamhathcock/sharpcompress/commit/efae8328a9801e9729f2ec54b9a305c3392c055c) Don't throw an exception when flushing an EntryStream - [`6dd5da4`](https://github.com/adamhathcock/sharpcompress/commit/6dd5da48f7fcae7122a66f2eaff15acdd9ef5c4f) Added test that calls EntryStream.Flush() - [`53ad00c`](https://github.com/adamhathcock/sharpcompress/commit/53ad00cdc49a4a266b17d73b5bb9901bb7567098) Use soft tabs ### 📊 Changes **4 files changed** (+84 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Common/EntryStream.cs` (+1 -3) ➕ `tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs` (+57 -0) 📝 `tests/SharpCompress.Test/Tar/TarReaderTests.cs` (+26 -0) ➕ `tests/TestArchives/Archives/Tar.ContainsTarGz.tar` (+0 -0) </details> ### 📄 Description 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](https://referencesource.microsoft.com/#mscorlib/system/security/cryptography/cryptostream.cs,141)). 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](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.flush?view=netframework-4.7.2#System_IO_Stream_Flush) 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:18:37 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1017