I'm looking at using JSZip
create a zip file on the file from various downstream files. Here is pseudo code for what I'm trying to do:
function* handler () {
const ids = this.request.body.ids;
const zip = new JSZip();
for (let i = 0; i < ids; i++) {
const r = yield request.get('/some/remote/service/' + ids[i]);
zip.file(ids[i], r.body);
}
this.body = zip.nodeStream():
}
But presumably this will require the contents of all the files to be in memory at once, and won't start streaming until all the files are downloaded.
I realize I could optimize download time by doing something like:
const allFiles = yield ids.map((id) => request.get('/some/remote/service/' + id));
for (let i = 0; i < ids.length; i++) zip.file(ids[i], allFiles[i]);
But mainly I'm hoping for a way to only hold one file in memory at a time and stream the result through zip back to the client. Is that possible with JSZip
?