'How to convert the accumulated data of 'fflate' zip stream to blob for download

The application will create a large data in GBs. After storing to an array and the passing to zip() worked to a limit , which the heap filled. So my plan is

  • convert each line using ZipDeflate .push()
  • ondata store to an array
  • convert the array to blob that can be saved as a zip file

findings

  • data is an Uint8Array
  • new Blob([mergedDatas]) was not a zip file
  const zippedData = []
  const zip = new Zip();
  zip.ondata = (err, data, final) => {
        if (!err) {
          zippedData.push(data)
          if (final) {
            // Here I want the zipped data to be downloaded
          }
        }
      };
    
  const frames = new ZipDeflate(exportName + '.lsf', {
    level: 9,
  });
 zip.add(frames);
 frames.push(header); // this is a uintd binary data
// there is lot of loops and things that will generate GBs of data eg. below two lines
 frames.push(numberToBytes(branch.name));
 frames.push(ColorByteArray);
// end of loop 
 frames.push(new Uint8Array(0), true);
 zip.end();


Solution 1:[1]

Finally found myself


  let processedZipStreams = [];
  zip.ondata = async (err, dat, final) => {
    if (err) {
    } else {
      processedZipStreams.push(dat);
      generatorInstance.next();
      if (final) {
        SaveAs(
          new Blob(processedZipStreams, { type: 'application/octet-stream' }),
          exportName,
          true
        );
        callback(100);
        const duration = performance.now() - start;
        console.log(duration / 1000);
      }
    }
  };

processed ZipStreams can be packed to a blob and downloaded

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 6by3