11cb0ef41Sopenharmony_ci"use strict"; 21cb0ef41Sopenharmony_civar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 31cb0ef41Sopenharmony_ci if (k2 === undefined) k2 = k; 41cb0ef41Sopenharmony_ci var desc = Object.getOwnPropertyDescriptor(m, k); 51cb0ef41Sopenharmony_ci if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { 61cb0ef41Sopenharmony_ci desc = { enumerable: true, get: function() { return m[k]; } }; 71cb0ef41Sopenharmony_ci } 81cb0ef41Sopenharmony_ci Object.defineProperty(o, k2, desc); 91cb0ef41Sopenharmony_ci}) : (function(o, m, k, k2) { 101cb0ef41Sopenharmony_ci if (k2 === undefined) k2 = k; 111cb0ef41Sopenharmony_ci o[k2] = m[k]; 121cb0ef41Sopenharmony_ci})); 131cb0ef41Sopenharmony_civar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 141cb0ef41Sopenharmony_ci Object.defineProperty(o, "default", { enumerable: true, value: v }); 151cb0ef41Sopenharmony_ci}) : function(o, v) { 161cb0ef41Sopenharmony_ci o["default"] = v; 171cb0ef41Sopenharmony_ci}); 181cb0ef41Sopenharmony_civar __importStar = (this && this.__importStar) || function (mod) { 191cb0ef41Sopenharmony_ci if (mod && mod.__esModule) return mod; 201cb0ef41Sopenharmony_ci var result = {}; 211cb0ef41Sopenharmony_ci if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 221cb0ef41Sopenharmony_ci __setModuleDefault(result, mod); 231cb0ef41Sopenharmony_ci return result; 241cb0ef41Sopenharmony_ci}; 251cb0ef41Sopenharmony_ciObject.defineProperty(exports, "__esModule", { value: true }); 261cb0ef41Sopenharmony_ciexports.req = exports.json = exports.toBuffer = void 0; 271cb0ef41Sopenharmony_ciconst http = __importStar(require("http")); 281cb0ef41Sopenharmony_ciconst https = __importStar(require("https")); 291cb0ef41Sopenharmony_ciasync function toBuffer(stream) { 301cb0ef41Sopenharmony_ci let length = 0; 311cb0ef41Sopenharmony_ci const chunks = []; 321cb0ef41Sopenharmony_ci for await (const chunk of stream) { 331cb0ef41Sopenharmony_ci length += chunk.length; 341cb0ef41Sopenharmony_ci chunks.push(chunk); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci return Buffer.concat(chunks, length); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ciexports.toBuffer = toBuffer; 391cb0ef41Sopenharmony_ci// eslint-disable-next-line @typescript-eslint/no-explicit-any 401cb0ef41Sopenharmony_ciasync function json(stream) { 411cb0ef41Sopenharmony_ci const buf = await toBuffer(stream); 421cb0ef41Sopenharmony_ci const str = buf.toString('utf8'); 431cb0ef41Sopenharmony_ci try { 441cb0ef41Sopenharmony_ci return JSON.parse(str); 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci catch (_err) { 471cb0ef41Sopenharmony_ci const err = _err; 481cb0ef41Sopenharmony_ci err.message += ` (input: ${str})`; 491cb0ef41Sopenharmony_ci throw err; 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ciexports.json = json; 531cb0ef41Sopenharmony_cifunction req(url, opts = {}) { 541cb0ef41Sopenharmony_ci const href = typeof url === 'string' ? url : url.href; 551cb0ef41Sopenharmony_ci const req = (href.startsWith('https:') ? https : http).request(url, opts); 561cb0ef41Sopenharmony_ci const promise = new Promise((resolve, reject) => { 571cb0ef41Sopenharmony_ci req 581cb0ef41Sopenharmony_ci .once('response', resolve) 591cb0ef41Sopenharmony_ci .once('error', reject) 601cb0ef41Sopenharmony_ci .end(); 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci req.then = promise.then.bind(promise); 631cb0ef41Sopenharmony_ci return req; 641cb0ef41Sopenharmony_ci} 651cb0ef41Sopenharmony_ciexports.req = req; 661cb0ef41Sopenharmony_ci//# sourceMappingURL=helpers.js.map