UNPKG

1.16 kBJavaScriptView Raw
1"use strict";
2/**
3 * A collection of functions to make working with http easier
4 * @module
5 */
6var __importDefault = (this && this.__importDefault) || function (mod) {
7 return (mod && mod.__esModule) ? mod : { "default": mod };
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.download = void 0;
11const fs_1 = __importDefault(require("fs"));
12const got_1 = __importDefault(require("got"));
13/**
14 * Download a file to disk
15 *
16 * @param {string} uri - the URI to request
17 * @param {string} destination - Where to store file locally
18 * @param {Object} [options] - additional download options
19 * @param {Object} [options.headers] - headers to include in the request
20 * @returns {Promise<undefined>} - resolves when the download is complete
21 */
22exports.download = (uri, destination, options = {}) => {
23 const file = fs_1.default.createWriteStream(destination);
24 return new Promise((resolve, reject) => {
25 got_1.default.stream(uri, options)
26 .on('error', reject)
27 .pipe(file);
28 file
29 .on('finish', resolve)
30 .on('error', reject);
31 });
32};
33//# sourceMappingURL=http.js.map
\No newline at end of file