Touffy / client-zip

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

[QUESTION] How to stream zip without first loading all of it in memory #74

Closed ZefQ closed 1 year ago

ZefQ commented 1 year ago

First of, thank you for this lib. I found this while browsing a zip64 feature request for the Conflux project.

Anyway I have a large number of ~100 Mb files lets say a total of 40 Gb that i would like to stream to the client as a zip, but i can´t figure out how to achieve that. i have read some of your closed issues to try to get an idea but i cant seem to get it to work. This is kind of what i got but i tried a couple of different inputs to the generate function your DownloadStream for example.

const downloadAllClientZip = async () => {
  const files = await getFiles(); // load some file objects from a rest api

  const blob = await downloadZip(generate(files)).blob();

  const link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = `${params[0]}.zip`;
  link.click();
  URL.revokeObjectURL(link.href);
  link.remove();
};

async function* generate(files) {
  for (const { href, folder, title } of files)
    yield {
      input: await fetch(href),
      name: `${folder}/${title}`,
    };
}

:bow: