# stream-to-array

> Concatenate a readable stream's data into a single array

Latest version **2.3.0** (published 2016-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-to-array
pnpm add stream-to-array
yarn add stream-to-array
bun add stream-to-array
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2016-02-28 |
| First published | 2013-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/stream-to-array) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 99 |
| Author | Jonathan Ong |
| Maintainers | jongleberry, dougwilson |
| Keywords | stream, streams, buffer, array, concat |

## Links

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

## Dependencies (1)

- [any-promise](https://npm.io/package/any-promise.md) ^1.1.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K 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

## Recent versions

- 2.3.0 (latest) — 2016-02-28
- 2.2.1 — 2016-01-14
- 2.2.0 — 2015-11-05
- 2.1.0 — 2015-10-21
- 2.0.2 — 2014-08-29
- 2.0.1 — 2014-08-29
- 2.0.0 — 2014-07-11
- 1.0.0 — 2013-12-04

## README

# Stream to Array

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

Concatenate a readable stream's data into a single array.

You may also be interested in:

- [raw-body](https://github.com/stream-utils/raw-body) for strings

## API

```js
var toArray = require('stream-to-array')
```

### toArray([stream], [callback(err, arr)])

Returns all the data objects in an array.
This is useful for streams in object mode if you want to just use an array.

```js
var stream = new Stream.Readable()
toArray(stream, function (err, arr) {
  assert.ok(Array.isArray(arr))
})
```

If `stream` is not defined, it is assumed that `this` is a stream.

```js
var stream = new Stream.Readable()
stream.toArray = toArray
stream.toArray(function (err, arr) {

})
```

If `callback` is not defined, then it returns a promise.

```js
toArray(stream)
  .then(function (parts) {

  })
```

If you want to return a buffer, just use `Buffer.concat(arr)`

```js
toArray(stream)
  .then(function (parts) {
    var buffers = []
    for (var i = 0, l = parts.length; i < l ; ++i) {
      var part = parts[i]
      buffers.push((part instanceof Buffer) ? part : new Buffer(part))
    }
    return Buffer.concat(buffers)
  })
```

[npm-image]: https://img.shields.io/npm/v/stream-to-array.svg?style=flat-square
[npm-url]: https://npmjs.org/package/stream-to-array
[github-tag]: http://img.shields.io/github/tag/stream-utils/stream-to-array.svg?style=flat-square
[github-url]: https://github.com/stream-utils/stream-to-array/tags
[travis-image]: https://img.shields.io/travis/stream-utils/stream-to-array.svg?style=flat-square
[travis-url]: https://travis-ci.org/stream-utils/stream-to-array
[coveralls-image]: https://img.shields.io/coveralls/stream-utils/stream-to-array.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/stream-utils/stream-to-array?branch=master
[david-image]: http://img.shields.io/david/stream-utils/stream-to-array.svg?style=flat-square
[david-url]: https://david-dm.org/stream-utils/stream-to-array
[license-image]: http://img.shields.io/npm/l/stream-to-array.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/stream-to-array.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/stream-to-array

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