Open jfoclpf opened 2 years ago
Created PR https://github.com/kevva/download/pull/228 which addresses the current issue
For big files, it may be useful to use a progress bar. You must install also module progress
.
const download = require('download')
const ProgressBar = require('progress')
const writeStream = fs.createWriteStream('http://unicorn.com/foo.zip')
const readStream = download('dist/foo.zip')
readStream.on('response', function (res) {
const len = parseInt(res.headers['content-length'], 10)
const bar = new ProgressBar(' downloading [:bar] :rate/bps :percent :etas', {
complete: '=',
incomplete: ' ',
width: 20,
total: len
})
readStream.on('data', function (chunk) {
writeStream.write(chunk)
bar.tick(chunk.length)
})
readStream.on('end', function () {
console.log('Download done with success\n')
writeStream.end()
})
})
For big files, it may be useful to use a progress bar. You must install also module
progress
.const download = require('download') const ProgressBar = require('progress') const writeStream = fs.createWriteStream('http://unicorn.com/foo.zip') const readStream = download('dist/foo.zip') readStream.on('response', function (res) { const len = parseInt(res.headers['content-length'], 10) const bar = new ProgressBar(' downloading [:bar] :rate/bps :percent :etas', { complete: '=', incomplete: ' ', width: 20, total: len }) readStream.on('data', function (chunk) { writeStream.write(chunk) bar.tick(chunk.length) }) readStream.on('end', function () { console.log('Download done with success\n') writeStream.end() }) })
Isn't the create write stream to be the download path while the first parameter in the download function is the URL?
No, it might seem strange but I am almost sure the code is correct, I tested myself.
I had to switch it to work fine tho .
Any tips on how to use progress bar or % for the download (very useful for big files)?