
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
Buffer a readable stream into memory.
import {readBody} from 'read-body'
// Read the stream into a buffer (limit of 1mb).
let buffer = await readBody(stream)
// Clear the cached buffer.
stream.body = null
// Read the same stream again, but with a limit of 100mb.
buffer = await readBody(stream, 1e8)
// Parse the stream as JSON.
const json = await stream.json()
// Do the two lines above in one fell swoop.
buffer = await readBody(stream, {json: true, maxBytes: 1e8})
When readBody is called, the stream has its body property
set to a promise that resolves with a buffer. By default,
the buffer is limited to 1mb max. If the limit is exceeded,
the promise is rejected, the buffer is destroyed, and the
stream is drained. The body property is used to prevent
reading the same stream more than once.
Instead of passing json: true via the options object,
try calling the .json() method which is available on
the stream once the promise is resolved.
For convenience, the bytes and maxBytes properties
are added to the stream once the promise is resolved.
Shortcut for readBody(stream, {json: true}).
import {readJson} from 'read-body'
// Read the stream into a JSON value (limit of 1mb).
const json = await readJson(stream)
FAQs
Buffer a readable stream into memory.
We found that read-body demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.