I'm creating an updater that downloads application files using the Node module request
. How can I use chunk.length
to estimate the remaining file size? Here's part of my code:
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
});
I wrote a module that just does what you want: status-bar.
Using the cool node-request-progress module, you could do something like this in es2015:
In case someone wants to know the progress without the use of other library but only request, then you can use the following method :
The
received_bytes
variable saves the total of every sent chunk length and according to thetotal_bytes
, the progress is retrieven.This should get you the total you want:
I get a content length of
9404541
If you are using "request" module and want to display downloading percentage without using any extra module, you can use the following code: