dotnet / dotnet/aspnetcore

Configurable buffer size for TransmitDataStreamToJS.TransmitStreamAsync

Open
#55,283 0 comments 0 reactions 0 assignees View on GitHub
area-blazor enhancement feature-blazor-jsinterop
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

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.

I have a Blazor WASM application that allows users to decrypt files in the browser before saving them to the host. This is currently accomplished by buffering the entire plaintext in-memory before clicking an invisible anchor to prompt a download to the host machine. See:

- https://learn.microsoft.com/en-us/aspnet/core/blazor/file-downloads?view=aspnetcore-8.0#download-from-a-stream

I'd like to move away from buffering the entire plaintext by streaming the plaintext, as it's decrypted, to a service worker. See:

- https://github.com/jimmywarting/StreamSaver.js/
- https://github.com/ProtonMail/WebClients/blob/d1a23fc2c4ab1e1632118baaee6f2531022ae4cf/applications/drive/src/app/store/_downloads/fileSaver/fileSaver.ts#L40

The issue I'm facing is my ciphertexts are decrypted in discrete chunks of a configurable size. My current plaintext chunk size is `65_600`, but the idea is I can tune this to be whatever is optimal for my use-case and the platforms I support. Whereas `Microsoft.AspNetCore.Components.TransmitDataStreamToJS.TransmitStreamAsync` defines a constant buffer size of `32 * 1024` or `32_768`. See:

- https://github.com/dotnet/aspnetcore/blob/7033ec7f402fa4b7df2bf72a5e3dff1df6831f57/src/Components/Shared/src/TransmitDataStreamToJS.cs#L17

My current options are to reduce the chunk size defined by my application or to implement some additional buffering within the custom "decryption stream" I've created on the C# side.

### Describe the solution you'd like

Would it be possible to define a custom buffer size when streaming to JS? Perhaps an override in the .csproj, similar to other WASM memory settings?

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.