herozion 1.1.9 → 1.1.10
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/install.js +6 -5
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -72,8 +72,9 @@ function download(url, destPath, redirectCount = 0) {
|
|
|
72
72
|
|
|
73
73
|
const file = fs.createWriteStream(destPath);
|
|
74
74
|
res.pipe(file);
|
|
75
|
-
|
|
76
|
-
file.
|
|
75
|
+
// Use .once() — "finish" and "error" each fire at most once on a WriteStream.
|
|
76
|
+
file.once("finish", () => file.close(resolve));
|
|
77
|
+
file.once("error", (err) => {
|
|
77
78
|
fs.unlink(destPath, () => {});
|
|
78
79
|
reject(err);
|
|
79
80
|
});
|
|
@@ -95,9 +96,9 @@ function downloadText(url, redirectCount = 0) {
|
|
|
95
96
|
return reject(new Error(`HTTP ${res.statusCode} — failed to download ${url}`));
|
|
96
97
|
}
|
|
97
98
|
let data = "";
|
|
98
|
-
res.on("data", (chunk) => { data += chunk; });
|
|
99
|
-
res.
|
|
100
|
-
res.
|
|
99
|
+
res.on("data", (chunk) => { data += chunk; }); // "data" fires N times — .on() is correct
|
|
100
|
+
res.once("end", () => resolve(data));
|
|
101
|
+
res.once("error", reject);
|
|
101
102
|
}).on("error", reject);
|
|
102
103
|
});
|
|
103
104
|
}
|