UNPKG

@gatling.io/cli

Version:

Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).

26 lines (25 loc) 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.downloadFile = void 0; const make_fetch_happen_1 = __importDefault(require("make-fetch-happen")); const fs_1 = __importDefault(require("fs")); const util_1 = __importDefault(require("util")); const stream_1 = __importDefault(require("stream")); const proxy_1 = require("../proxy"); const pipeline = util_1.default.promisify(stream_1.default.pipeline); const fetchOptionsFromNpmConfiguration = () => ({ proxy: proxy_1.proxyConfiguration.httpsProxyUrl || proxy_1.proxyConfiguration.proxyUrl, noProxy: proxy_1.proxyConfiguration.noProxyHosts }); const downloadFile = async (url, targetFile) => { const options = fetchOptionsFromNpmConfiguration(); const response = await (0, make_fetch_happen_1.default)(url, options); if (!response.ok) { throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`); } await pipeline(response.body, fs_1.default.createWriteStream(targetFile)); }; exports.downloadFile = downloadFile;