You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doesn't get the length of stream automatically using request. #26
Gets the length of the stream automatically if you're using the request or http module. You can also pass the length on initiation. Progress-stream will also check to see if the stream already has a length property.
I tried this example in the readme and length was 0(default value) not the length of the stream.
@vibhor1997a , I solving this problem by adding a HEAD request before and set the length of the bar.
here is my code:
asyncfunctiondownloadVideoFromURL(url,fullPath){function_getContentLength(url){returnnewPromise((resolve,reject)=>{request.head(url,{},(err,res)=>{if(err)reject(err)resolve(res.headers['content-length'])})})}constcontentLength=await_getContentLength(url);conststr=progress({time: 1000,length: contentLength});str.on('progress',(progress)=>{console.log(`downloading video from url: ${url}, ${Math.round(progress.percentage)+'%'}`);})returnnewPromise((resolve,_)=>{request(url).pipe(str).pipe(fs.createWriteStream(fullPath)).on('close',resolve);});}
Activity
Hatuw commentedon Apr 16, 2020
@vibhor1997a , I solving this problem by adding a
HEADrequest before and set the length of the bar.here is my code: