raw-body
- Version 4.0.0
- Published
- 30.1 kB
- 2 dependencies
- MIT license
Install
npm i raw-bodyyarn add raw-bodypnpm add raw-bodyOverview
Get and validate the raw body of a readable stream.
Index
Functions
function getRawBody
getRawBody: { (stream: NodeRawBodyStream, callback: Callback<Buffer>): void; ( stream: any, options: Encoding | Readonly<Options & { encoding: Encoding }>, callback: Callback<string> ): void; (stream: any, options: Readonly<Options>, callback: Callback<Buffer>): void; ( stream: any, options: Encoding | Readonly<Options & { encoding: Encoding }> ): Promise<string>; (stream: any, options?: Readonly<Options>): Promise<Buffer>;};Gets the entire buffer of a node stream as a
Buffer, delivered to the callback. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.Gets the entire buffer of a node stream decoded as a string with the given encoding, delivered to the callback. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.
Gets the entire buffer of a node stream decoded as a string with the given encoding. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.
Gets the entire buffer of a node stream as a
Buffer. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.
function getRawBodyWeb
getRawBodyWeb: { (stream: WebRawBodyStream, callback: Callback<Buffer>): void; ( stream: WebRawBodyStream, options: Encoding | Readonly<Options & { encoding: Encoding }>, callback: Callback<string> ): void; ( stream: WebRawBodyStream, options: Readonly<Options>, callback: Callback<Buffer> ): void; ( stream: WebRawBodyStream, options: Encoding | Readonly<Options & { encoding: Encoding }> ): Promise<string>; (stream: WebRawBodyStream, options?: Readonly<Options>): Promise<Buffer>;};Gets the entire buffer of a web
ReadableStreamas aBuffer, delivered to the callback. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.Gets the entire buffer of a web
ReadableStreamdecoded as a string with the given encoding, delivered to the callback. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.Gets the entire buffer of a web
ReadableStreamdecoded as a string with the given encoding. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.Gets the entire buffer of a web
ReadableStreamas aBuffer. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.
Interfaces
interface Decoder
interface Decoder {}A streaming decoder, turning body chunks into a string.
interface Options
interface Options {}property decoder
decoder?: (encoding: string) => Decoder;A function that receives the encoding and returns the decoder used to turn the body into a string, instead of the built-in
TextDecoder. Compatible withiconv-lite'sgetDecoder. Throwing signals the encoding is unsupported.
property encoding
encoding?: Encoding | false | null;The encoding to use to decode the body into a string. By default, a
Bufferinstance will be returned when no encoding is specified. Most likely, you wantutf-8, so setting encoding totruewill decode asutf-8. You can use any encoding supported byTextDecoder.false(or any other falsy value) disables decoding, returning aBuffer.
property length
length?: number | string | null;The expected length of the stream.
property limit
limit?: number | string | null;The byte limit of the body. This is the number of bytes or any string format supported by
bytes, for example1000,'500kb'or'3mb'.
interface RawBodyError
interface RawBodyError extends Error {}property code
code?: string;The error code, when there is one, e.g.
ECONNABORTEDfor aborted requests.
property encoding
encoding?: string;The encoding.
property expected
expected?: number;property length
length?: number;The expected length of the stream.
property limit
limit?: number;The limit in bytes.
property received
received?: number;The received bytes.
property status
status?: number;The corresponding status code for the error. Errors created by
raw-bodyalways carry one, but errors passed through from the stream or a custom decoder may not.
property statusCode
statusCode?: number;property type
type?: RawBodyErrorType;The error type. Set on every error created by
raw-body, but absent on errors passed through from the stream or a custom decoder.
Type Aliases
type Encoding
type Encoding = string | true;The encoding to decode the body with.
truedecodes asutf-8.
type NodeRawBodyStream
type NodeRawBodyStream = NodeJS.ReadableStream | Readable;The stream types accepted by
getRawBody.
type RawBodyErrorType
type RawBodyErrorType = | 'encoding.unsupported' | 'entity.too.large' | 'request.aborted' | 'request.size.invalid' | 'stream.encoding.set' | 'stream.not.readable';The
typevalues of the errors created byraw-body.
type WebRawBodyStream
type WebRawBodyStream = ReadableStream<Uint8Array | string>;The stream types accepted by
getRawBodyWeb.
Package Files (1)
Dependencies (2)
Dev Dependencies (11)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/raw-body.
- Markdown[](https://www.jsdocs.io/package/raw-body)
- HTML<a href="https://www.jsdocs.io/package/raw-body"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2606 ms. - Missing or incorrect documentation? Open an issue for this package.
