Package Exports
- @arcjet/body
- @arcjet/body/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@arcjet/body) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@arcjet/body
Arcjet utilities for getting the body from a Node.js Stream.
Installation
npm install -S @arcjet/bodyExample
import { readBody } from "../index";
// Some stream.Readable-like object, such as node's `http.IncomingMessage`
const request = new IncomingMessage();
// Returns the body as a utf-8 encoded string
const body = await readBody(request, { limit: 1024 });
console.log(body);Implementation
The implementation of this library is based on the raw-body package. Licensed MIT with licenses included in our source code.
We've chosen to re-implement the logic to read the body from the stream to keep
the dependency tree for our packages as light as possible. Our implementation only
provides the functionality that we need, specifically it excludes the functionality
to return the stream as a buffer and always parses it as a utf-8 string. The interface
was also changed to only support promises rather than the sync implementation provided by raw-body.
License
Licensed under the Apache License, Version 2.0.