我正在创建一个使用 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
});
这应该可以得到你想要的总数:
req.on( 'response', function ( data ) {
console.log( data.headers[ 'content-length' ] );
} );
我得到的内容长度为9404541
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)