voinznext 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +21 -2
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
module.exports = { downloadLatest };
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require("child_process");
|
|
5
|
-
const { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync, renameSync } = require("fs");
|
|
5
|
+
const { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync, renameSync, unlinkSync } = require("fs");
|
|
6
6
|
const https = require("https");
|
|
7
7
|
const { join } = require("path");
|
|
8
8
|
const { platform, arch } = require("process");
|
|
@@ -54,9 +54,28 @@ function download(url, dest) {
|
|
|
54
54
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
const totalBytes = parseInt(res.headers['content-length'], 10);
|
|
59
|
+
let downloadedBytes = 0;
|
|
60
|
+
let lastPercent = -1;
|
|
61
|
+
|
|
62
|
+
res.on('data', (chunk) => {
|
|
63
|
+
downloadedBytes += chunk.length;
|
|
64
|
+
if (totalBytes) {
|
|
65
|
+
const percent = Math.floor((downloadedBytes / totalBytes) * 100);
|
|
66
|
+
if (percent !== lastPercent && percent % 10 === 0) {
|
|
67
|
+
process.stdout.write(`\r ● Downloading... ${percent}%`);
|
|
68
|
+
lastPercent = percent;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
57
73
|
const file = createWriteStream(dest);
|
|
58
74
|
res.pipe(file);
|
|
59
|
-
file.on("finish", () =>
|
|
75
|
+
file.on("finish", () => {
|
|
76
|
+
if (totalBytes) process.stdout.write(`\r ✔ Download complete\n`);
|
|
77
|
+
file.close(resolve);
|
|
78
|
+
});
|
|
60
79
|
file.on("error", reject);
|
|
61
80
|
}).on("error", reject);
|
|
62
81
|
});
|