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
Using the cool node-request-progress module, you could do something like this in es2015:
import { createWriteStream } from 'fs'
import request from 'request'
import progress from 'request-progress'
progress(request('http://foo.com/bar.zip'))
.on('progress', state => {
console.log(state)
/*
{
percentage: 0.5, // Overall percentage (between 0 to 1)
speed: 554732, // The download speed in bytes/sec
size: {
total: 90044871, // The total payload size in bytes
transferred: 27610959 // The transferred payload size in bytes
},
time: {
elapsed: 36.235, // The total elapsed seconds since the start (3 decimals)
remaining: 81.403 // The remaining seconds to finish (3 decimals)
}
}
*/
})
.on('error', err => console.log(err))
.on('end', () => {})
.pipe(createWriteStream('bar.zip'))