Closed numairawan closed 2 years ago
why is your archive splited up in multiple chunks? anyhow. i would recommend you to keep using the server if possible to save the zip instead of emulating a server using streamsaver.js and a service workers
but if you insist on using streamsaver anyway then you would have to make something like:
const chunks = [
'https://example.com/',
'https://example.com/',
]
function concatenateRequests(requests) {
const ts = new TransformStream()
const pump = () => {
const it = requests.next()
if (it.done) return ts.writable.close();
fetch(it.value).then(res => {
console.log(res.body);
return res.body.pipeTo(ts.writable, { preventClose: true })
}).then(pump, ts.writable.abort.bind(ts.writable));
}
pump();
return ts.readable;
}
concatenateRequests(chunks.values()).pipeTo(streamSaver.createWritableStream('archive.zip'))
Thanks :)