| 273 | ).then(() => files.map(filename => this.filePath(filename))); |
| 274 | } |
| 275 | download(url, dest) { |
| 276 | if (DEBUG) console.error(`Downloading ${url}`); |
| 277 | |
| 278 | return new Promise((resolve, reject) => { |
| 279 | const file = fs.createWriteStream(dest); |
| 280 | |
| 281 | request(url) |
| 282 | .pipe(file) |
| 283 | .on("error", err => { |
| 284 | fs.unlink(dest); |
| 285 | reject(err); |
| 286 | }); |
| 287 | |
| 288 | file.on("finish", () => file.close(resolve)); |
| 289 | }).then(() => { |
| 290 | if (DEBUG) console.error(`Download Complete ${url}`); |
| 291 | }); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | function pathExists(file) { |