Node Unzipper-如何知道它已经完成

问题描述 投票:0回答:1

我正在尝试使用解压缩节点模块来提取和处理许多文件(确切数目是未知的)。但是,我似乎无法弄清楚如何知道何时处理所有文件。到目前为止,我的代码如下所示:

s3.getObject(params).createReadStream()
.pipe(unzipper.Parse())
.on('entry', async (entry) => {
    var fileName = entry.path;
    if (fileName.match(someRegex)) {
        await processEntry(entry);
        console.log("Uploaded");
    } else {
        entry.autodrain();
        console.log("Drained");
    }
});

[我正试图弄清如何知道解压缩已遍历所有文件(即,不再有entry事件即将来临] 所有entry处理程序都已完成,以便我知道已经处理完我关心的所有文件。

[我已经尝试过closefinish事件,但是当我遇到这些事件时,它们都在console.log("Uploaded");打印之前触发,因此似乎不正确。

帮助?

node.js unzip synchronous
1个回答
0
投票

直接from the docs

解析器像其他流一样发出finisherror事件。解析器还为这两个事件提供了一个Promise包装,以便轻松折叠到现有的基于Promise的结构中。]

实施例:

fs.createReadStream('path/to/archive.zip')
  .pipe(unzipper.Parse())
  .on('entry', entry => entry.autodrain())
  .promise()
  .then( () => console.log('done'), e => console.log('error',e));
© www.soinside.com 2019 - 2024. All rights reserved.