(filePath, url)
| 72 | |
| 73 | // Utility: Download file |
| 74 | const downloadFile = (filePath, url) => { |
| 75 | if (!filePath || !url) { |
| 76 | if (config.verbose) { |
| 77 | console.log('skipping malformed download request: ', filePath, url); |
| 78 | } |
| 79 | return Promise.resolve(); |
| 80 | } |
| 81 | |
| 82 | return new Promise((resolve, reject) => { |
| 83 | https.get(url, (response) => { |
| 84 | if (response.statusCode < 200 || response.statusCode > 299) { |
| 85 | reject(new Error(`HTTP Error ${response.statusCode} while fetching '${filePath}'`)); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | const writeStream = fsSync.createWriteStream(filePath); |
| 90 | response.pipe(writeStream); |
| 91 | |
| 92 | writeStream.on('finish', () => { |
| 93 | if (config.verbose) { |
| 94 | console.log(`${LOG_TAG} \tFinished downloading ${url} to ${filePath}`); |
| 95 | } |
| 96 | resolve(); |
| 97 | }); |
| 98 | |
| 99 | writeStream.on('error', reject); |
| 100 | }).on('error', reject); |
| 101 | }); |
| 102 | }; |
| 103 | |
| 104 | // Utility: Get local file hash (Git blob format) |
| 105 | const getLocalHash = (filePath) => { |
no test coverage detected