node-archiver icon indicating copy to clipboard operation
node-archiver copied to clipboard

Finalize() not working for multiple files in zip

Open Qirsia opened this issue 5 years ago • 6 comments

  var archive = archiver('zip');
      archive.on('error', (err) => {
        console.log(err);
        throw err
      })
 for (const report of generatedReports) {
     //report is excel work book object
      const buffer = await report.writeToBuffer()
      archive.append(buffer, {
        name: name
      })
}
console.log("before finalize")
await archive.finalize()
console.log("after finalize")

I am appending multiple excel buffers to the archive, if the number of files I am appending is small ~ 15, it will finalize. But if I append ~20 files, it reaches "before finalize" but never reaches "after finalize"

I am not sure what I am doing wrong, I have tried with zip options {store: true}, it's able to zip more files but still silently fails.

Help!

Qirsia avatar Feb 04 '20 22:02 Qirsia

I come with the same question. If filesize large then 1M, it will no response.

leohxj avatar Aug 08 '20 07:08 leohxj

I have had a similar problem, but was able to solve it with the code linked below. You can try to give it a shot, maybe some similar solution will work for you too :)

handleNext is name of the linked function, its calling itself until all files were appended, then finalizes image

trboltom avatar Aug 09 '20 07:08 trboltom

Any updates on this issue, running into same?

vikasgarghb avatar Oct 29 '20 20:10 vikasgarghb

@Qirsia is that the whole code for the archiver? You need to store or pipe the archive somewhere before finilizing.

JekRock avatar Nov 24 '20 11:11 JekRock

I ran into the same problem when calling archive.pipe(...) after await archive.finalize(). Calling archive.pipe(...) as early as possible solved the issue for me.
Seems to be an easy mistake to make.

marcusleg avatar Mar 12 '21 10:03 marcusleg

I got the same problem for multiple files, I increased the highWaterMark according to the objects size, and it solved this issue for me.

const highWaterMark = 1024 * 1024 * objects.length
const zipStream = archiver('zip', {
  zlib: { level: 9 },
  highWaterMark
})

LuckyLuo avatar Nov 08 '23 00:11 LuckyLuo