Created
August 2, 2019 15:22
-
-
Save Craigson/0b5efa807c192886627c89199fee8014 to your computer and use it in GitHub Desktop.
http download progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var progress = require('progress-stream'); | |
var fs = require('fs'); | |
const http = require('http'); | |
// const file = fs.createWriteStream('mov.mp4'); | |
const request = http.get( | |
'http://10.0.1.177:8080/ccapi/ver100/contents/sd/100CANON/MVI_0656.MP4', | |
function(response) { | |
var stat = fs.statSync(filename); | |
var str = progress({ | |
length: stat.size, | |
time: 100 /* ms */ | |
}); | |
str.on('progress', function(progress) { | |
console.log(progress); | |
/* | |
{ | |
percentage: 9.05, | |
transferred: 949624, | |
length: 10485760, | |
remaining: 9536136, | |
eta: 42, | |
runtime: 3, | |
delta: 295396, | |
speed: 949624 | |
} | |
*/ | |
}); | |
response.pipe(file).pipe(fs.createWriteStream('mov.mp4')); | |
console.log('done'); | |
} | |
); | |
// fs.createReadStream(filename) | |
// .pipe(str) | |
// .pipe(fs.createWriteStream(output)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment