Crypter
Crypter copied to clipboard
[Feature] Investigate streamed downloads
Description
The primary reason for limiting file transfers to 100 MB is to accommodate mobile browsers. The majority of mobile browsers are still 32-bit, meaning they are limited to 2 GB of memory.
Currently, the sequence of events for downloading an encrypted file goes:
- Download the full ciphertext into memory.
- Decrypt the file ciphertext to plaintext, in memory.
- Copy the entire plaintext to the page as a base64 blob.
- Download the blog to the device.
A 100 MB file may actually have a 300 MB memory footprint. The last thing I want is for an OutOfMemoryException
to occur during file downloads.
Now consider this answer from SO: https://stackoverflow.com/a/39685380
and this repository: https://github.com/jimmywarting/StreamSaver.js
It should be possible to perform streaming downloads. Which means a much smaller memory footprint during download; potentially up to an arbitrary chunk size. Which means I could drastically increase the file transfer size limit.
I intend to create a NuGet package for this issue. If anyone else gets to it first, please drop a link here!
Edit: I may not be working on this after all. Time constraints.
Proton also has a good implementation. They add an Iframe to the page, instead of depending on a separate, static site to host the service worker.
https://github.com/ProtonMail/WebClients/blob/main/applications/drive/src/app/store/_downloads/fileSaver/fileSaver.ts
https://github.com/Jack-Edwards/BlazorStreamSaver/tree/add-blazor-binding
Proof of concept is working on this branch: https://github.com/Crypter-File-Transfer/Crypter/tree/feature/streamed-downloads
Remaining work:
- Fine-tune various buffer sizes for best performance.
- Fall-back to an array buffer in case the browser does not support service workers or response streaming.
- Wait for .NET 9.0 to be fully released. Response streaming in Blazor WASM is currently only available in the .NET 9.0 pre-releases.
#715
Blocked by #717
Resolved! These changes are currently in the stable
branch.