mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Added time estimate etc to the github mod downloading
This commit is contained in:
1 parent
1fcd91342f
commit
c4fb313aef
1 file changed
+8
-2
@@ -147,14 +147,20 @@ module.exports.addMod = function(term, instance){
|
|||||||
console.log("Downloading " + url);
|
console.log("Downloading " + url);
|
||||||
let file = fs.createWriteStream(modDirectory + name);
|
let file = fs.createWriteStream(modDirectory + name);
|
||||||
let bytesDownloaded = 0;
|
let bytesDownloaded = 0;
|
||||||
|
let downloadStartTime = Date.now();
|
||||||
https.get(url, function(response) {
|
https.get(url, function(response) {
|
||||||
|
let bytesToDownload = response.headers['content-length'];
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
response.on("data", chunk => {
|
response.on("data", chunk => {
|
||||||
bytesDownloaded += chunk.length;
|
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 => {
|
}).on("end", x => {
|
||||||
sLog.clear();
|
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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user