1- import * as http from " http" ;
2- import * as https from " https" ;
3- import type { Readable } from " stream" ;
1+ import * as http from ' http' ;
2+ import * as https from ' https' ;
3+ import type { Readable } from ' stream' ;
44
55export async function toBuffer ( stream : Readable ) : Promise < Buffer > {
6- let length = 0 ;
7- const chunks : Buffer [ ] = [ ] ;
8- for await ( const chunk of stream ) {
9- length += chunk . length ;
10- chunks . push ( chunk ) ;
11- }
12- return Buffer . concat ( chunks , length ) ;
6+ let length = 0 ;
7+ const chunks : Buffer [ ] = [ ] ;
8+ for await ( const chunk of stream ) {
9+ length += chunk . length ;
10+ chunks . push ( chunk ) ;
11+ }
12+ return Buffer . concat ( chunks , length ) ;
1313}
1414
1515// eslint-disable-next-line @typescript-eslint/no-explicit-any
1616export async function json ( stream : Readable ) : Promise < any > {
17- const buf = await toBuffer ( stream ) ;
18- return JSON . parse ( buf . toString ( 'utf8' ) ) ;
17+ const buf = await toBuffer ( stream ) ;
18+ return JSON . parse ( buf . toString ( 'utf8' ) ) ;
1919}
2020
2121export function req (
2222 url : string | URL ,
2323 opts : https . RequestOptions = { }
2424) : Promise < http . IncomingMessage > {
2525 return new Promise ( ( resolve , reject ) => {
26- const href = typeof url === 'string' ? url : url . href ;
27- ( href . startsWith ( " https:" ) ? https : http )
26+ const href = typeof url === 'string' ? url : url . href ;
27+ ( href . startsWith ( ' https:' ) ? https : http )
2828 . request ( url , opts , resolve )
29- . once ( " error" , reject )
29+ . once ( ' error' , reject )
3030 . end ( ) ;
3131 } ) ;
32- }
32+ }
0 commit comments