(url: string, dest: string, fileOut?: fs.WriteStream)
| 296 | |
| 297 | // Download the update file |
| 298 | const downloadFile = (url: string, dest: string, fileOut?: fs.WriteStream): Promise<void> => { |
| 299 | return new Promise((resolve, reject) => { |
| 300 | const file = fileOut || fs.createWriteStream(dest); |
| 301 | https |
| 302 | .get(url, (response) => { |
| 303 | if (response.statusCode === 302 || response.statusCode === 301) { |
| 304 | // Handle redirect |
| 305 | return downloadFile(response.headers.location!, dest, file).then(resolve).catch(reject); |
| 306 | } |
| 307 | |
| 308 | response.on("end", () => { |
| 309 | file.close(); |
| 310 | resolve(); |
| 311 | }); |
| 312 | response.pipe(file); |
| 313 | }) |
| 314 | .on("error", (err) => { |
| 315 | fs.unlink(dest, () => {}); // Delete the file async |
| 316 | reject(err); |
| 317 | }); |
| 318 | }); |
| 319 | }; |
| 320 | |
| 321 | if (fs.existsSync(zipPath)) { |
| 322 | fs.rmSync(zipPath); |
no test coverage detected