icsharpcode / SharpZipLib

#ziplib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
http://icsharpcode.github.io/SharpZipLib/
MIT License
3.73k stars 976 forks source link

BZip2AsyncOutputStream #877

Open logiclrd opened 2 months ago

logiclrd commented 2 months ago

Is your feature request related to a problem? Please describe.

I want to stream BZip2-compressed data from a result handler in an ASP.NET Core web app. The ASP.NET Core response stream only supports async operations. I found that BZip2OutputStream is inherently synchronous, so I copied it into my project and created BZip2AsyncOutputStream by means of straightforwardly replacing all calls to synchronously output bytes with async calls instead. A couple of cases required async-over-sync (explicit .Wait), since e.g. disposing the stream results in synchronous .Write and .Flush calls, but in the main operation it's all async. It seems to work. No idea on the impact on efficiency.

Would there be any interest in a contribution of this class?

Describe the solution you'd like

I'd like to make a PR that adds BZip2AsyncOutputStream to SharpZipLib so that other people who, like me, want to stream BZip2-compressed data in contexts that don't support synchronous I/O have an option. But I don't want to make a PR if it is unwelcome. :-)

Describe alternatives you've considered

There aren't really any alternatives, as I understand it. Async code simply requires you to be async up and down the call stack.

Tags

BZip2

Additional context

No response