Tag: 进度

请求中获取Node.js的下载进度

我正在创build一个使用Node模块request下载应用程序文件的更新程序。 如何使用chunk.length来估计剩余的文件大小? 这是我的代码的一部分: var file_url = 'http://foo.com/bar.zip'; var out = fs.createWriteStream('baz.zip'); var req = request({ method: 'GET', uri: file_url }); req.pipe(out); req.on('data', function (chunk) { console.log(chunk.length); }); req.on('end', function() { //Do something });