raw-body

  • Version 2.5.2
  • Published
  • 25.8 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

function getRawBody

getRawBody: {
(
stream: Readable,
callback: (err: getRawBody.RawBodyError, body: Buffer) => void
): void;
(
stream: Readable,
options:
| getRawBody.Encoding
| (getRawBody.Options & { encoding: getRawBody.Encoding }),
callback: (err: getRawBody.RawBodyError, body: string) => void
): void;
(
stream: Readable,
options: getRawBody.Options,
callback: (err: getRawBody.RawBodyError, body: Buffer) => void
): void;
(
stream: Readable,
options:
| getRawBody.Encoding
| (getRawBody.Options & { encoding: getRawBody.Encoding })
): Promise<string>;
(stream: Readable, 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 want utf-8, so setting encoding to true will decode as utf-8. You can use any type of encoding supported by iconv-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 example 1000, '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 onejsDocs.io badgeto 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>