1 import { Readable } from 'stream';
3 declare namespace getRawBody {
4 export type Encoding = string | true;
6 export interface Options {
8 * The expected length of the stream.
10 length?: number | string | null;
12 * The byte limit of the body. This is the number of bytes or any string
13 * format supported by `bytes`, for example `1000`, `'500kb'` or `'3mb'`.
15 limit?: number | string | null;
17 * The encoding to use to decode the body into a string. By default, a
18 * `Buffer` instance will be returned when no encoding is specified. Most
19 * likely, you want `utf-8`, so setting encoding to `true` will decode as
20 * `utf-8`. You can use any type of encoding supported by `iconv-lite`.
22 encoding?: Encoding | null;
25 export interface RawBodyError extends Error {
31 * The expected length of the stream.
44 * The corresponding status code for the error.
56 * Gets the entire buffer of a stream either as a `Buffer` or a string.
57 * Validates the stream's length against an expected length and maximum
58 * limit. Ideal for parsing request bodies.
60 declare function getRawBody(
62 callback: (err: getRawBody.RawBodyError, body: Buffer) => void
65 declare function getRawBody(
67 options: (getRawBody.Options & { encoding: getRawBody.Encoding }) | getRawBody.Encoding,
68 callback: (err: getRawBody.RawBodyError, body: string) => void
71 declare function getRawBody(
73 options: getRawBody.Options,
74 callback: (err: getRawBody.RawBodyError, body: Buffer) => void
77 declare function getRawBody(
79 options: (getRawBody.Options & { encoding: getRawBody.Encoding }) | getRawBody.Encoding
82 declare function getRawBody(
84 options?: getRawBody.Options