UNPKG

resedit-cli

Version:

Command-line tool for editing Windows Resource data in executable binaries

38 lines (37 loc) 1.2 kB
import * as http from 'http'; import * as https from 'https'; import * as log from '../log.js'; export default function requestSimpleUsingHttp(url, opt, cb) { log.debug('[sign] Use native Node.js http/https library'); const options = opt; const httpCallback = (res) => { const results = []; res.on('data', (chunk) => { results.push(chunk); }); res.on('end', () => { var _a; const buff = Buffer.concat(results); if (res.statusCode < 200 || res.statusCode >= 400) { cb(new Error(`Server error ${res.statusCode} ${(_a = res.statusMessage) !== null && _a !== void 0 ? _a : ''}`), res.headers, buff); } else { cb(null, res.headers, buff); } }); }; let req; if (/^https:/.test(url)) { req = https.request(url, options, httpCallback); } else { req = http.request(url, options, httpCallback); } req.on('error', (e) => { cb(e, {}, Buffer.from('')); }); if (typeof opt.body !== 'undefined') { req.write(opt.body); } req.end(); }