如何根据节点 webkit 中下载的文件显示进度条?
var https = require('https');
var fs = require('fs');
var exec = require('child_process').exec;
var file = fs.createWriteStream("update_setup.exe");
var len = 0;
var request = https.get(url + 'appdata/update_setup.exe', function (response) {
response.pipe(file);
response.on('data', function (chunk) {
file.write(chunk);
len += chunk.length;
var percent = (len / response.headers['content-length']) * 100;
});
file.on('finish', function () {
setTimeout(function () { win.close(); exec('update_setup.exe'); }, 1000);
});
});