diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index 488207d1..f7fc0294 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -147,14 +147,20 @@ module.exports.addMod = function(term, instance){ console.log("Downloading " + url); let file = fs.createWriteStream(modDirectory + name); let bytesDownloaded = 0; + let downloadStartTime = Date.now(); https.get(url, function(response) { + let bytesToDownload = response.headers['content-length']; response.pipe(file); response.on("data", chunk => { bytesDownloaded += chunk.length; - sLog("Downloading "+name+": "+formatBytes(bytesDownloaded)); + let downloadTimeElapsed = Date.now() - downloadStartTime; + let bytesPerSecond = bytesDownloaded / (downloadTimeElapsed/1000); + let timeToComplete = Math.floor((bytesToDownload - bytesDownloaded)/bytesPerSecond); + sLog("Downloading "+name+" "+(bytesDownloaded/bytesToDownload*100).toPrecision(3)+"% ("+formatBytes(bytesDownloaded)+" / "+formatBytes(bytesToDownload)+")\r\n"+ + "about "+timeToComplete+" seconds remaining ("+formatBytes(bytesPerSecond)+"/s)"); }).on("end", x => { sLog.clear(); - console.log(""); // because sLog.clear() doesn't seem to do the job of ending the line properly + console.log(" Downloaded in "+moment.utc(moment.duration(Date.now()-downloadStartTime).as('milliseconds')).format('mm:ss')); // because sLog.clear() doesn't seem to do the job of ending the line properly }); }); }