Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "queue closed error" occurs at when using archiver.file module to compress files

Tags:

node.js

I am trying to download multiple files as zip in nodejs using archiver. This is my code:

exports.downloadAllFiles = function(req,res){
    var archive = archiver('zip', {
        gzip: true,
        zlib: { level: 9 } // Sets the compression level.
    });
    var output = fs.createWriteStream( "/home/files/Downloads/demo.zip");

    archive.pipe(output);

    demoDb.findOne({ caseguid: req.params.id }, function(err, data) { 
        if (err) {
            res.json(HttpStatus.INTERNAL_SERVER_ERROR, {});
        } else {
            if(data){
                data.Files.forEach(function(singleDoc){
                       archive.append(fs.createReadStream(singleDoc.filePath), { name: singleDoc.fileName })

                })

            }

         }

    })
    archive.finalize();
};

This is the error stack:

{ Error: queue closed
    at Archiver.append (/home/node_modules/archiver/lib/core.js:552:24)
    at Promise.<anonymous> (/home/server/controllers/caseController.js:1722:25)
    at Promise.<anonymous> (/home/node_modules/mpromise/lib/promise.js:177:8)
    at emitOne (events.js:96:13)
    at Promise.emit (events.js:188:7)
    at Promise.emit (/home/node_modules/mpromise/lib/promise.js:84:38)
    at Promise.fulfill (/home/node_modules/mpromise/lib/promise.js:97:20)
    at /home/node_modules/mongoose/lib/query.js:1406:13
    at model.Document.init (/home/node_modules/mongoose/lib/document.js:254:11)
    at completeOne (/home/node_modules/mongoose/lib/query.js:1404:10)
    at Immediate.cb (/home/node_modules/mongoose/lib/query.js:1158:11)
    at Immediate.<anonymous> (/homenode_modules/mquery/lib/utils.js:137:16)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5) message: 'queue closed', code: 'QUEUECLOSED', data: undefined }
like image 602
Prakash Avatar asked Oct 19 '25 02:10

Prakash


1 Answers

Probably the line archive.finalize() is being executed before your callback be completed. Try to move your archive.finalize to inside your callback.

like image 169
Leonardo Souza Avatar answered Oct 21 '25 18:10

Leonardo Souza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!