# fast-stream-to-buffer

> Consume a stream of data into a binary Buffer as efficiently as possible

Latest version **1.0.0** (published 2018-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-stream-to-buffer
pnpm add fast-stream-to-buffer
yarn add fast-stream-to-buffer
bun add fast-stream-to-buffer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-21 |
| First published | 2018-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Thomas Watson |
| Maintainers | watson |
| Keywords | stream, readable, buffer, string, convert, converter, ReadableStream, concat |

## Links

- npm: https://www.npmjs.com/package/fast-stream-to-buffer
- Repository: https://github.com/watson/fast-stream-to-buffer
- Homepage: https://github.com/watson/fast-stream-to-buffer#readme
- Issues: https://github.com/watson/fast-stream-to-buffer/issues
- npm.io page: https://npm.io/package/fast-stream-to-buffer

## Dependencies (1)

- [end-of-stream](https://npm.io/package/end-of-stream.md) ^1.4.1

## 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.0.0 (latest) — 2018-06-21

## README

# fast-stream-to-buffer

Consume a stream of data into a binary Buffer as efficiently as
possible.

[![Build status](https://travis-ci.org/watson/fast-stream-to-buffer.svg?branch=master)](https://travis-ci.org/watson/fast-stream-to-buffer)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install fast-stream-to-buffer --save
```

## Usage

Process an abitrary readable stream:

```js
const streamToBuffer = require('fast-stream-to-buffer')

streamToBuffer(stream, function (err, buf) {
  if (err) throw err
  console.log(buf.toString())
})
```

Or use the `onStream()` helper function:

```js
const http = require('http')
const streamToBuffer = require('fast-stream-to-buffer')

// `http.get` expects a callback as the 2nd argument that will be called
// with a readable stream of the response
http.get('http://example.com', streamToBuffer.onStream(function (err, buf) {
  if (err) throw err
  console.log(buf.toString('utf8'))
})
```

## API

### `streamToBuffer(stream, callback)`

Arguments:

- `stream` - Any readable stream
- `callback` - A callback function which will be called with an optional
  error object as the first argument and a buffer containing the content
  of the `stream` as the 2nd

### `fn = streamToBuffer.onStream(callback)`

Returns a function `fn` which expects a readable stream as its only
argument. When called, it will automatically call `streamToBuffer()`
with the stream as the first argument and the `callback` as the second.

## License

MIT

---
_Source: https://npm.io/package/fast-stream-to-buffer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
