(url: string)
| 8 | const AdmZip = require("adm-zip"); |
| 9 | |
| 10 | function httpsGetBuffer(url: string) { |
| 11 | const _get = ( |
| 12 | url: string, |
| 13 | resolve: (b: Buffer) => void, |
| 14 | reject: (e: Error) => void |
| 15 | ) => { |
| 16 | // User-Agent is needed for GitHub request |
| 17 | const options: https.RequestOptions = { |
| 18 | headers: { |
| 19 | "User-Agent": "node-https", |
| 20 | "Content-Type": "application/json; charset=utf-8", |
| 21 | }, |
| 22 | }; |
| 23 | https |
| 24 | .get(url, options, function (res) { |
| 25 | if ( |
| 26 | (res.statusCode === 301 || res.statusCode === 302) && |
| 27 | res.headers.location |
| 28 | ) { |
| 29 | _get(res.headers.location, resolve, reject); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | const data: Uint8Array[] = []; |
| 34 | res.on("data", function (chunk: Uint8Array) { |
| 35 | data.push(chunk); |
| 36 | }); |
| 37 | res.on("end", function () { |
| 38 | const buffer = Buffer.concat(data); |
| 39 | if (res.statusCode === 200) { |
| 40 | resolve(buffer); |
| 41 | } else { |
| 42 | reject( |
| 43 | new Error( |
| 44 | `Status code: ${ |
| 45 | res.statusCode |
| 46 | }\nResponse: ${buffer.toString()}` |
| 47 | ) |
| 48 | ); |
| 49 | } |
| 50 | }); |
| 51 | }) |
| 52 | .on("error", function (err) { |
| 53 | reject(new Error(`Error: ${err}`)); |
| 54 | }); |
| 55 | }; |
| 56 | |
| 57 | return new Promise<Buffer>((resolve, reject) => { |
| 58 | _get(url, resolve, reject); |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | async function httpsGetJson(url: string) { |
| 63 | const buffer = await httpsGetBuffer(url); |
no test coverage detected