节点js文件系统:未调用可读stream的结束事件

我试图提取一个.tar文件(从一个目录打包),然后检查提取的目录中的文件的名称。 我正在使用tar-fs来提取tar文件,然后使用fs.createReadStream来处理数据。 这是迄今为止我所得到的:

fs.createReadStream(req.files.file.path) .pipe(tar.extract(req.files.file.path + '0')) .on('error', function() { errorMessage = 'Failed to extract file. Please make sure to upload a tar file.'; }) .on('entry', function(header, stream, callback) { console.error(header); stream.on('end', function() { console.error("this is working"); }); }) .on('end', function() { //the one did not get called console.error('end'); }) ; 

我希望提取整个文件夹,然后检查文件名称。 那么,我还没有那么远

就我的理解,我在pipe道后面得到了一个可读的stream。 一个可读的stream有一个结束事件? 我的问题是,为什么代码中的end事件没有被调用?

谢谢!

聆听可写入stream的finish事件。 当end()被调用并且对input的处理完成时这被触发。 更多的在这里 。

 .on('finish', function() { console.error('end'); })