W przypadku gdy ktoś chce wiedzieć postępy bez użycia innej biblioteki, ale tylko wniosek, wówczas można użyj następującej metody:
function downloadFile(file_url , targetPath){
// Save variable to know progress
var received_bytes = 0;
var total_bytes = 0;
var req = request({
method: 'GET',
uri: file_url
});
var out = fs.createWriteStream(targetPath);
req.pipe(out);
req.on('response', function (data) {
// Change the total bytes value to get progress later.
total_bytes = parseInt(data.headers['content-length' ]);
});
req.on('data', function(chunk) {
// Update the received bytes
received_bytes += chunk.length;
showProgress(received_bytes, total_bytes);
});
req.on('end', function() {
alert("File succesfully downloaded");
});
}
function showProgress(received,total){
var percentage = (received * 100)/total;
console.log(percentage + "% | " + received + " bytes out of " + total + " bytes.");
// 50% | 50000 bytes received out of 100000 bytes.
}
downloadFile("https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg","c:/path/to/local-image.jpg");
zmienna received_bytes
zapisuje sumie każdego wysłanego długości bryłkach i zgodnie z total_bytes
, pro gress jest retrieven.
mam wewnątrz .zip: node-webkit.app/a kiedy wyodrębniam dane-> NIE MOŻNA uruchomić .app już:/mój kod :: fs.writeFileSync (frameZipFilePath, dane, "binary"); var zip = new AdmZip (frameZipFilePath); zip.extractAllTo (ścieżka.resolve ("", "tmp"), prawda); – miukki