From a4a653d8fa53525d866a08fd7e516bff65396605 Mon Sep 17 00:00:00 2001 From: Pierce Date: Mon, 28 Jan 2019 17:26:04 -0500 Subject: [PATCH] Download progress event --- components/handler.js | 9 ++++++++- package.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/handler.js b/components/handler.js index abcdf78..d182701 100644 --- a/components/handler.js +++ b/components/handler.js @@ -24,6 +24,13 @@ function downloadAsync (url, directory, name) { }); }); + _request.on('data', (data) => { + event.emit('download-status', { + "current": Math.round(fs.statSync(path.join(directory, name))["size"] / 10000), + "total": data.length + }) + }); + const file = fs.createWriteStream(path.join(directory, name)); _request.pipe(file); @@ -223,7 +230,7 @@ module.exports.makePackage = async function(versions, os) { module.exports.extractPackage = function(root, clientPackage) { return new Promise(async resolve => { if(clientPackage.startsWith('http')) { - await downloadAsync(clientPackage, root, "clientPackage.zip") + await downloadAsync(clientPackage, root, "clientPackage.zip"); clientPackage = path.join(root, "clientPackage.zip") } new zip(clientPackage).extractAllTo(root, true); diff --git a/package.json b/package.json index b3a449e..11c2867 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "1.2.0", + "version": "1.2.1", "description": "Module that downloads Minecraft assets and runs Minecraft.", "main": "index.js", "dependencies": {