# @arcjet/body

> Arcjet utilities for extracting the body from a stream

Latest version **1.14.1** (published 2026-10-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @arcjet/body
pnpm add @arcjet/body
yarn add @arcjet/body
bun add @arcjet/body
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2026-10-07 |
| First published | 2024-08-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.21.0 <23 \|\| >=24.5.0 |
| Dependencies | 0 |
| Unpacked size | 23.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 685 |
| Author | Arcjet |
| Maintainers | quinn-arcjet, davidmytton |
| Keywords | arcjet, body, stream, util, utility |

## Links

- npm: https://www.npmjs.com/package/@arcjet/body
- Repository: https://github.com/arcjet/arcjet-js
- Homepage: https://arcjet.com
- Issues: https://github.com/arcjet/arcjet-js/issues
- npm.io page: https://npm.io/package/@arcjet/body

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.14.1 (latest) — 2026-10-07
- 1.10.0-rc.1 (rc) — 2026-08-07
- 1.14.0 — 2026-10-01
- 1.13.0 — 2026-09-16
- 1.12.0 — 2026-09-08
- 1.11.0 — 2026-08-26
- 1.10.0 — 2026-08-11
- 1.10.0-rc.0 — 2026-08-04
- 1.9.1 — 2026-07-15
- 1.9.0 — 2026-07-15
- 1.8.0 — 2026-07-07
- 1.8.0-rc.0 — 2026-07-07
- 1.7.0 — 2026-07-06
- 1.7.0-rc.1 — 2026-07-06
- 1.7.0-rc.0 — 2026-07-03
- … 41 more at https://npm.io/package/@arcjet/body/versions

## README

<!-- trunk-ignore-all(markdownlint/MD001) -->
<!-- trunk-ignore-all(markdownlint/MD024) -->

<a href="https://arcjet.com" target="_arcjet-home">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
    <img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
  </picture>
</a>

# `@arcjet/body`

<p>
  <a href="https://www.npmjs.com/package/@arcjet/body">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fbody?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
      <img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fbody?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
    </picture>
  </a>
</p>

[Arcjet][arcjet] utilities for getting the body from a stream.

- [npm package (`@arcjet/body`)](https://www.npmjs.com/package/@arcjet/body)
- [GitHub source code (`body/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/body)

## What is this?

This is an internal utility to help us read streams from various frameworks.
It’s in part a fork of [`stream-utils/raw-body`][node-raw-body].
We chose to fork so that we can cut away functionality that we do not use
and keep our dependency tree as light as possible.
Specifically it always parses the stream as a UTF-8 string instead of a `Buffer`
and only supports promises instead of callbacks.

## When should I use this?

You should not use this but use [`stream-utils/raw-body`][node-raw-body] or one
of the alternatives instead.
This package matches our current needs which are likely different from yours.

## Install

This package is ESM only.
Install with npm in Node.js:

```sh
npm install @arcjet/body
```

## Use

```ts
import fs from "node:fs";
import { readBody } from "@arcjet/body";

const body = await readBody(fs.createReadStream("example.ts"), { limit: 1024 });
console.log(body);
```

## API

This package exports the identifiers
[`readBodyWeb`][api-read-body-web] and
[`readBody`][api-read-body].
There is no default export.

This package exports the [TypeScript][] types
[`ReadBodyOpts`][api-read-body-opts] and
[`ReadableStreamLike`][api-readable-stream-like].

### `ReadBodyOpts`

Configuration (TypeScript type).

###### Fields

- `expectedLength` (`number`, optional)
  — length of the stream in bytes;
  rejects an error if the contents of the stream do not add up to this length;
  useful when the exact size is known
- `limit` (`number`, required)
  — limit of the body in bytes;
  rejects an error if the body ends up being larger than this limit;
  used to prevent reading too much data from malicious clients.

### `ReadableStreamLike`

Minimal Node.js stream interface (TypeScript type).

```ts
interface ReadableStreamLike {
  on?: EventHandlerLike | null | undefined;
  readable?: boolean | null | undefined;
  removeListener?: EventHandlerLike | null | undefined;
}
```

### `readBodyWeb(stream, options)`

Read the body of a
[web stream][web-stream].

###### Parameters

- `stream` (`ReadableStream`)
  — stream
- `options` ([`ReadBodyOpts`][api-read-body-opts], required)
  — configuration

###### Returns

Promise that resolves to a concatenated body (`Promise<string>`).

### `readBody(stream, options)`

Read the body of a Node.js stream.

###### Parameters

- `stream` (`ReadableStream`)
  — stream
- `options` ([`ReadBodyOpts`][api-read-body-opts], required)
  — configuration

###### Returns

Promise that resolves to a concatenated body (`Promise<string>`).

## License

[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]

Derivative work based on [`raw-body`][node-raw-body] licensed under
[MIT][node-raw-body-license] © Jonathan Ong and Douglas Christopher Wilson.
Our work removes features that we do not use: no buffers, no sync interface.
It adds a version for web streams.

[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
[api-read-body-opts]: #readbodyopts
[api-read-body-web]: #readbodywebstream-options
[api-read-body]: #readbodystream-options
[api-readable-stream-like]: #readablestreamlike
[arcjet]: https://arcjet.com
[node-raw-body-license]: https://github.com/stream-utils/raw-body/blob/191e4b6/LICENSE
[node-raw-body]: https://github.com/stream-utils/raw-body/blob/191e4b6/test/index.js
[typescript]: https://www.typescriptlang.org
[web-stream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream

---
_Source: https://npm.io/package/@arcjet/body · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
