Touffy / client-zip

A client-side streaming ZIP generator
MIT License
342 stars 22 forks source link

Add a ServiceWorker demo #9

Closed Touffy closed 3 years ago

Touffy commented 3 years ago

Creating a Blob is the only way to get a download when running client-zip directly in the browser window's JavaScript context. But that means the whole archive needs to be in memory and the download won't start until then.

It would be more efficient (particularly if you bundle lots of files (or large ones) from HTTP requests) to use a ServiceWorker to stream the archive. It also allows means there is no unseemly creating and clicking of a Blob URL link and subsequent revocation. Using local Files in the archive would be more difficult, though, and won't be included in the demo (it's also not included in the worker script distribution of the library).

The streaming ServiceWorker usage is only a little more complicated than the basic Blob usage, but it needs a demo so that more users of client-zip will take that step confidently.