I'm using unzip2 module https://github.com/glebdmitriew/node-unzip-2 to do zip file stream unzipping, but on getting zip entries, I got a problem.
我正在使用unzip2模块https://github.com/glebdmitriew/node-unzip-2来解压缩zip文件流,但是在获取zip条目时,我遇到了问题。
My code is as below:
我的代码如下:
var fs = require('fs');
var entries = [];
var srcStream = fs.createReadStream('test.zip');
srcStream.pipe(unzip.Parse())
.on('entry', function(entry) {
entries.push(entry.path);
entry.autodrain();
})
.on('finish', function() {
console.log(entries);
});
But the output is always "[]", it seems when "finish" event got, the operation on "entry" event is not finished.
但是输出总是“[]”,似乎当“完成”事件得到时,“进入”事件的操作没有完成。
Is there any solutions that I can get all the entry list?
有什么解决方案可以获得所有参赛名单吗?
1 个解决方案
#1
2
Use "close" event instead of "finish" may solve this issue.
使用“关闭”事件而不是“完成”可能会解决此问题。
var fs = require('fs');
var entries = [];
var srcStream = fs.createReadStream('test.zip');
srcStream.pipe(unzip.Parse())
.on('entry', function(entry) {
entries.push(entry.path);
entry.autodrain();
})
.on('close', function() {
console.log(entries);
});
#1
2
Use "close" event instead of "finish" may solve this issue.
使用“关闭”事件而不是“完成”可能会解决此问题。
var fs = require('fs');
var entries = [];
var srcStream = fs.createReadStream('test.zip');
srcStream.pipe(unzip.Parse())
.on('entry', function(entry) {
entries.push(entry.path);
entry.autodrain();
})
.on('close', function() {
console.log(entries);
});