StreamSaver.js lets web apps write large streams to the user filesystem without holding entire files in memory. It uses service workers and download response semantics.
Overview
StreamSaver.js addresses saving large or continuous data from the browser when holding everything in RAM or a single blob is impractical. It creates a writable stream path toward the file system by emulating how servers trigger downloads with response headers, aided by a service worker.
The library complements FileSaver-style blob saves for client-generated content. Documentation advises preferring real server-side Content-Disposition headers when the bytes already come from your backend, and using StreamSaver when you cannot change headers or data is produced in the browser.
Setup involves registering a service worker, often via a hosted mitm helper in secure contexts, then transferring a ReadableStream to the worker which opens a download in the browser. HTTPS is recommended to avoid popup blockers and to keep the helper page active. User interaction may be required to start writes in some insecure cases.
Examples in the project cover piping fetch bodies, mediaRecorder output, typed input, blobs, and zipped multiple files. Authors note newer native file system APIs may reduce the need for this pattern over time.
Key features
- Stream-to-file browser saves
- Service worker mediated downloads
- Large data without full RAM use
- createWriteStream style API
- Works with fetch and MediaRecorder
- HTTPS-oriented setup guidance
- Example pipelines for zip and torrent
- Client-generated content focus
Use cases
- Saving long generated downloads
- Piping fetch bodies to files
- Recording media straight to disk
- Browser apps with big exports