I want a simple API to stream the data for a file download in JavaScript

Submitted by Erik Jensen

It's currently possible to use a Blob URL to initiate the download of data held in memory. This is a useful feature to allow the to user to download data that is generated or processed by JavaScript. However, this only works for smaller amounts of data that can fit in RAM. When retrieving larger amounts of data (e.g., via a WebRTC data channel, or over a WebSocket), there's no way to allow the user to download the data without first buffering it all and creating a Blob.

I'd like a simple API that allows me to initiate a download with a suggested filename and expected size, triggering a download through the browser's standard download UI, and allowing me to feed in data as it becomes available. The simplest solution might be to support calling createObjectURL with a ReadableStream, though it doesn't look like that would provide a way to specify the expected total size.

Tagged
JavaScript