odi*_*tla 6 tar node.js node.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');
})
;
Run Code Online (Sandbox Code Playgroud)
我希望提取整个文件夹,然后检查文件名.好吧,我还没到那么远......
根据我的理解,我在管道后面有一个可读的流.可读流有结束事件吗?我的问题是,为什么end代码中的事件没有被调用?
谢谢!
has*_*sin 14
侦听finish可写流的事件.end()在调用并完成条目处理时触发此操作.更多关于它在这里.
.on('finish', function() {
console.error('end');
})
Run Code Online (Sandbox Code Playgroud)