PullFromJSDataStream should dispose IJSStreamReference internally
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
to keep my code works across platforms (both native and web) with as minimal effor as possible, i only accept `Stream` in my business logic to read files from the system. aside from using the `InputFile`, sometimes i also pass javascript's `File` object back to the c# side and cast it as `IJSStreamReference`.
while debugging, i found out that opening a read stream that way gives me `PullFromJSDataStream` instead of `BrowserFileStream`. correct me if im wrong here but after reading the code for some time, both implementations contains internal `IJSStreamReference` but only `BrowserFileStream` disposes it correctly.
### Describe the solution you'd like
as implemented by `BrowserFileStream`:
```cs
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}
_openReadStreamCts.Cancel();
_copyFileDataCts?.Cancel();
// If the browser connection is still live, notify the JS side that it's free to release the Blob
// and reclaim the memory. If the browser connection is already gone, there's no way for the
// notification to get through, but we don't want to fail the .NET-side disposal process for this.
try
{
_ = _jsStreamReference?.DisposeAsync().Preserve();
}
catch
{
}
_isDisposed = true;
base.Dispose(disposing);
}
```
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.