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

Add option to leave base stream open when disposing #779

Open
RayCarrot opened this issue Nov 11, 2023 · 5 comments
Open

Add option to leave base stream open when disposing #779

RayCarrot opened this issue Nov 11, 2023 · 5 comments

Comments

@RayCarrot
Copy link

Currently when disposing a compression stream such as ZlibStream it will also dispose the base stream you passed in. There are however times where you still want the base stream to remain open for further use and currently the only way I could find to do this is by creating a wrapping stream which doesn't dispose.
My suggestion would be to do what most built-in .NET streams do and have a parameter in the constructor called leaveOpen which indicates if the base stream you pass in should be left open even after disposing.

@adamhathcock
Copy link
Owner

We shouldn't be disposing streams we didn't create. A lot of StreamReaders and whatnot do dispose.

Please show what usage disposes unexpectedly

@RayCarrot
Copy link
Author

Your implementation of ZlibStream disposes the stream you pass in when disposing the ZlibStream. It happens here as far as I can tell.
I also checked the usage docs which say "I've decided to always close wrapped streams as of 0.21". The suggestion there is to use a wrapper stream, like I currently do, to avoid disposing. However I would suggest having the option to leave the stream open with a bool parameter just like the standard .NET libraries do. This avoids any additional overhead added by a wrapping stream.

@Erior
Copy link
Contributor

Erior commented Jan 11, 2024

Options "LeaveStreamOpen" true/false
Think we have tests regarding dispose, are you using ZlibStream directly or what is the scenario?

@RayCarrot
Copy link
Author

RayCarrot commented Jan 11, 2024

I am using ZlibStream directly, yes. And from what I can tell that's the only option in this library. Currently I made my own wrapper stream to avoid disposing, but I'd prefer if there was simply an option in the API directly like there is in the streams in the .NET libraries. There should be a difference between wanting to dispose the compression stream and whatever data it might be using and the base stream that you pass in.

@adamhathcock
Copy link
Owner

It can be a feature added, I think the compression streams directly haven't been changed to respond to that option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants