Skip to content

Should i call "zip.end()" with ondata finish === true? #65

Answered by 101arrowz
crapthings asked this question in Q&A
Discussion options

You must be logged in to vote

This only works because of the delay in the data arrival; you shouldn't use this solution. Instead, call zip.end() one time after you have called zip.add() with every file you need. You also have to make sure you don't call accidentally call zip.add() after zip.end(), e.g. if you put the add() calls into the event loop with async/await. Try this:

export function downloadAsZip (filename, downloads) {
  const fileStream = streamSaver.createWriteStream(`${filename}.zip`);
  const writer = fileStream.getWriter();
  const zip = new fflate.Zip();
  zip.ondata = writeStreamForDownload;
  downloads?.forEach(({ filename, downloadUrl }) => fetch(downloadUrl).then(pipeZipfile(filename)));
  // Now a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@crapthings
Comment options

Answer selected by 101arrowz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants