You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In addition to the error reported in #166, destroying a zip stream will not be handled properly internally:
Running this code (slightly different from the one in #166) will return the error bellow
'use strict'const{ promisify }=require('node:util')constZipStream=require('zip-stream')constsleep=promisify(setTimeout)asyncfunction*generateItems(){// Fake ressource usage. This will cause the process to never exit if the finally block is never executed.constinterval=setInterval(()=>{},10)console.error('generate start')leti=0try{while(i++<5){awaitsleep(1000)console.error('generate item',i)yield{data: Buffer.alloc(100_000_990),name: 'hello.txt',date: newDate()}}}finally{// Clean ressourcesclearInterval(interval)console.error('generate done',i)}}asyncfunctionpopulateZip(zip,asyncIterable){try{forawait(constitemofasyncIterable){awaitnewPromise((resolve,reject)=>{zip.entry(item.data,{name: item.name,date: item.date},(err,res)=>{if(err)reject(err)elseresolve(res)})})}zip.finalize()}catch(err){console.error('populateZip err',err)// Item generation failed or zip.entry() failedzip.destroy(err)}}asyncfunctionmain(){constzip=newZipStream({zlib: {level: 9}})populateZip(zip,generateItems())setTimeout(()=>{zip.destroy()// (1)},2000)zip.on('error',(err)=>{console.error('zip err',err)})zip.on('data',(chunk)=>{console.error('got zip chunk of size',chunk.length)})}voidmain()
generate start
generate item 1
got zip chunk of size 4
got zip chunk of size 2
got zip chunk of size 2
got zip chunk of size 2
got zip chunk of size 4
got zip chunk of size 4
got zip chunk of size 4
got zip chunk of size 4
got zip chunk of size 2
got zip chunk of size 2
got zip chunk of size 9
got zip chunk of size 16384
got zip chunk of size 16384
got zip chunk of size 16384
got zip chunk of size 16384
got zip chunk of size 16384
got zip chunk of size 12570
got zip chunk of size 2715
got zip chunk of size 4
got zip chunk of size 4
got zip chunk of size 4
got zip chunk of size 4
generate item 2
zip err NodeError: Cannot call write after a stream was destroyed
at doWrite (~/node_modules/readable-stream/lib/_stream_writable.js:409:38)
at writeOrBuffer (~/node_modules/readable-stream/lib/_stream_writable.js:398:5)
at ZipStream.Writable.write (~/node_modules/readable-stream/lib/_stream_writable.js:307:11)
at ZipStream.ArchiveOutputStream.write (~/node_modules/compress-commons/lib/archivers/archive-output-stream.js:116:36)
at ZipStream.ZipArchiveOutputStream._writeLocalFileHeader (~/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:390:8)
at ZipStream.ZipArchiveOutputStream._appendBuffer (~/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:74:8)
at ZipStream.ArchiveOutputStream.entry (~/node_modules/compress-commons/lib/archivers/archive-output-stream.js:86:10)
at ZipStream.entry (~/node_modules/zip-stream/index.js:166:49)
at ~/test.js:32:13
at new Promise (<anonymous>)
zip err NodeError: Cannot call write after a stream was destroyed
at doWrite (~/node_modules/readable-stream/lib/_stream_writable.js:409:38)
at writeOrBuffer (~/node_modules/readable-stream/lib/_stream_writable.js:398:5)
at ZipStream.Writable.write (~/node_modules/readable-stream/lib/_stream_writable.js:307:11)
at ZipStream.ArchiveOutputStream.write (~/node_modules/compress-commons/lib/archivers/archive-output-stream.js:116:36)
at ZipStream.ZipArchiveOutputStream._writeLocalFileHeader (~/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:393:8)
at ZipStream.ZipArchiveOutputStream._appendBuffer (~/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:74:8)
at ZipStream.ArchiveOutputStream.entry (~/node_modules/compress-commons/lib/archivers/archive-output-stream.js:86:10)
at ZipStream.entry (~/node_modules/zip-stream/index.js:166:49)
at ~/test.js:32:13
at new Promise (<anonymous>)
[... many more of these]
$ node -v
v16.19.1
The text was updated successfully, but these errors were encountered:
In addition to the error reported in #166, destroying a zip stream will not be handled properly internally:
Running this code (slightly different from the one in #166) will return the error bellow
The text was updated successfully, but these errors were encountered: