nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.74k stars 1.43k forks source link

Support async-only streams #1021

Open mycroes opened 1 year ago

mycroes commented 1 year ago

Async operations are used to avoid blocking threads on IO wait. Unfortunately NPOI currently only supports sync operations when writing documents to streams, which for instance doesn't work with AspNetCore Kestrel defaults that don't permit sync IO. Adding async variants of Write methods that take a Stream would permit consumers to choose between sync or async operation.

I'm willing to look into the changes required for async Writes and submit a PR if you're open to including this.

tonyqus commented 1 year ago

Thank you for your suggestion. I'm open to this async PR.

mycroes commented 1 year ago

I started working on this, but did some exception cleanup work first in PR #1034. For now I opted for 2 discrete paths (one sync, one async), extracting methods where duplicate code appears. I noticed SharpZipLib actually uses a single method for sync and async writes, which is implemented as async method which never runs async when invoked with sync intention. I didn't really feel very comfortable with that design though, so I decided for the seperate paths. I'm nowhere near done yet, but most of it is pretty smooth sailing.

tonyqus commented 1 year ago

1034 merged