# stream-with-known-length-to-buffer

> Convert a Readable Stream with a known length into a Buffer

Latest version **1.0.4** (published 2020-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-with-known-length-to-buffer
pnpm add stream-with-known-length-to-buffer
yarn add stream-with-known-length-to-buffer
bun add stream-with-known-length-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.4 |
| Published | 2020-07-17 |
| First published | 2015-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Feross Aboukhadijeh |
| Maintainers | feross |
| Keywords | stream, buffer, convert stream to buffer, convert, known length, length |

## Links

- npm: https://www.npmjs.com/package/stream-with-known-length-to-buffer
- Repository: https://github.com/feross/stream-with-known-length-to-buffer
- Issues: https://github.com/feross/stream-with-known-length-to-buffer/issues
- Funding: https://github.com/sponsors/feross
- npm.io page: https://npm.io/package/stream-with-known-length-to-buffer

## Dependencies (1)

- [once](https://npm.io/package/once.md) ^1.4.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2020-07-17
- 1.0.3 — 2019-06-28
- 1.0.2 — 2018-06-09
- 1.0.1 — 2018-03-15
- 1.0.0 — 2015-12-29

## README

# stream-with-known-length-to-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

[travis-image]: https://img.shields.io/travis/feross/stream-with-known-length-to-buffer/master.svg
[travis-url]: https://travis-ci.org/feross/stream-with-known-length-to-buffer
[npm-image]: https://img.shields.io/npm/v/stream-with-known-length-to-buffer.svg
[npm-url]: https://npmjs.org/package/stream-with-known-length-to-buffer
[downloads-image]: https://img.shields.io/npm/dm/stream-with-known-length-to-buffer.svg
[downloads-url]: https://npmjs.org/package/stream-with-known-length-to-buffer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com

#### Convert a Readable Stream with a known length into a Buffer

[![Sauce Test Status](https://saucelabs.com/browser-matrix/stream-with.svg)](https://saucelabs.com/u/stream-with)

This package converts a Readable Stream into a Buffer, with just one Buffer
allocation (excluding allocations done internally by the streams implementation).

This is lighter-weight choice than
[`stream-to-array`](https://github.com/stream-utils/stream-to-array) when the
total stream length is known in advance. This whole package is 15 lines.

This module is used by [WebTorrent](https://webtorrent.io).

### install

```
npm install stream-with-known-length-to-buffer
```

### usage

```js
var toBuffer = require('stream-with-known-length-to-buffer')

toBuffer(fs.createReadStream('file.txt'), 1000, function (err, buf) {
  if (err) return console.error(err.message)
  console.log(buf)
})
```

### license

MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).

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