raw-body
- Version 3.0.0
- Published
- 26.3 kB
- 4 dependencies
- MIT license
Install
npm i raw-body
yarn add raw-body
pnpm add raw-body
Overview
Get and validate the raw body of a readable stream.
Index
Functions
Interfaces
Type Aliases
Functions
function getRawBody
getRawBody: { ( stream: NodeJS.ReadableStream, callback: (err: getRawBody.RawBodyError, body: Buffer) => void ): void; ( stream: NodeJS.ReadableStream, options: | getRawBody.Encoding | (getRawBody.Options & { encoding: getRawBody.Encoding }), callback: (err: getRawBody.RawBodyError, body: string) => void ): void; ( stream: NodeJS.ReadableStream, options: getRawBody.Options, callback: (err: getRawBody.RawBodyError, body: Buffer) => void ): void; ( stream: NodeJS.ReadableStream, options: | getRawBody.Encoding | (getRawBody.Options & { encoding: getRawBody.Encoding }) ): Promise<string>; (stream: NodeJS.ReadableStream, options?: getRawBody.Options): Promise<Buffer>;};
Gets the entire buffer of a stream either as a
Buffer
or a string. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.
Interfaces
interface Options
interface Options {}
property encoding
encoding?: Encoding | null;
The encoding to use to decode the body into a string. By default, a
Buffer
instance will be returned when no encoding is specified. Most likely, you wantutf-8
, so setting encoding totrue
will decode asutf-8
. You can use any type of encoding supported byiconv-lite
.
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 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.
property statusCode
statusCode: number;
property type
type: string;
The error type.
Type Aliases
type Encoding
type Encoding = string | true;
Package Files (1)
Dependencies (4)
Dev Dependencies (12)
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[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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 851 ms. - Missing or incorrect documentation? Open an issue for this package.