in common/update-cli.js [20:44]
function downloadFile(url, destinationPath) {
return new Promise((resolve, reject) => {
const protocol = url.startsWith("https") ? https : http;
protocol.get(url, response => {
if (response.statusCode === 200) {
const file = fs.createWriteStream(destinationPath);
response.pipe(file);
file.on("finish", () => {
file.close(resolve);
});
} else if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
downloadFile(response.headers.location, destinationPath)
.then(resolve)
.catch(reject);
} else {
reject(new Error(`Failed to download file. Status code: ${response.statusCode}`));
}
}).on("error", err => {
fs.unlink(destinationPath, () => {
});
reject(err);
});
});
}