Crypter icon indicating copy to clipboard operation
Crypter copied to clipboard

[Feature] Investigate streamed downloads

Open Jack-Edwards opened this issue 1 year ago • 6 comments

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:

  1. Download the full ciphertext into memory.
  2. Decrypt the file ciphertext to plaintext, in memory.
  3. Copy the entire plaintext to the page as a base64 blob.
  4. 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.

Jack-Edwards avatar Jul 10 '23 03:07 Jack-Edwards

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.

Jack-Edwards avatar Jul 10 '23 04:07 Jack-Edwards

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

Jack-Edwards avatar Jul 12 '23 16:07 Jack-Edwards

https://github.com/Jack-Edwards/BlazorStreamSaver/tree/add-blazor-binding

Jack-Edwards avatar Nov 05 '23 02:11 Jack-Edwards

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.

Jack-Edwards avatar Apr 30 '24 03:04 Jack-Edwards

#715

Jack-Edwards avatar May 06 '24 01:05 Jack-Edwards

Blocked by #717

Jack-Edwards avatar May 13 '24 14:05 Jack-Edwards

Resolved! These changes are currently in the stable branch.

Jack-Edwards avatar Aug 31 '24 21:08 Jack-Edwards