forked from octokit/webhooks.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-payload.ts
More file actions
26 lines (23 loc) · 848 Bytes
/
get-payload.ts
File metadata and controls
26 lines (23 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// @ts-ignore to address #245
import AggregateError from "aggregate-error";
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/2075#issuecomment-817361886
// import type { IncomingMessage } from "node:http";
// declare module "node:http" {
// interface IncomingMessage {
// body?: string;
// }
// }
type IncomingMessage = any;
export function getPayload(request: IncomingMessage): Promise<Buffer> {
return new Promise((resolve, reject) => {
let data: Buffer[] = [];
// istanbul ignore next
request.on("error", (error: Error) => reject(new AggregateError([error])));
request.on("data", data.push.bind(data));
// istanbul ignore next
request.on("end", () =>
setImmediate(resolve, data.length === 1 ? data[0] : Buffer.concat(data)),
);
});
}