* Get a file by downloading it if necessary. * * @param {string} sourceURL URL to download the file from. * @param {string} destPath Destination file path on local filesystem.
(sourceURL, destPath)
| 144 | * @param {string} destPath Destination file path on local filesystem. |
| 145 | */ |
| 146 | async function maybeDownload(sourceURL, destPath) { |
| 147 | return new Promise(async (resolve, reject) => { |
| 148 | if (!fs.existsSync(destPath) || fs.lstatSync(destPath).size === 0) { |
| 149 | const localZipFile = fs.createWriteStream(destPath); |
| 150 | console.log(`Downloading file from ${sourceURL} ...`); |
| 151 | https.get(sourceURL, response => { |
| 152 | response.pipe(localZipFile); |
| 153 | localZipFile.on('finish', () => { |
| 154 | localZipFile.close(() => resolve()); |
| 155 | }); |
| 156 | localZipFile.on('error', err => reject(err)); |
| 157 | }); |
| 158 | } else { |
| 159 | return resolve(); |
| 160 | } |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Get extracted files. |
no outgoing calls
no test coverage detected