Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81139bd
commit 86c885e
Showing
33 changed files
with
1,915 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as http from "http"; | ||
import * as https from "https"; | ||
import type { Readable } from "stream"; | ||
|
||
export async function toBuffer(stream: Readable): Promise<Buffer> { | ||
let length = 0; | ||
const chunks: Buffer[] = []; | ||
for await (const chunk of stream) { | ||
length += chunk.length; | ||
chunks.push(chunk); | ||
} | ||
return Buffer.concat(chunks, length); | ||
} | ||
|
||
export async function json(stream: Readable): Promise<Record<string, string>> { | ||
const buf = await toBuffer(stream); | ||
return JSON.parse(buf.toString('utf8')); | ||
} | ||
|
||
export function req( | ||
url: string | URL, | ||
opts: https.RequestOptions | ||
): Promise<http.IncomingMessage> { | ||
return new Promise((resolve, reject) => { | ||
const href = typeof url === 'string' ? url : url.href; | ||
(href.startsWith("https:") ? https : http) | ||
.request(url, opts, resolve) | ||
.once("error", reject) | ||
.end(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.