Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Concatenate a readable stream's data into a single array.
JavaScript
branch: master
Failed to load latest commit information.
test update package
.gitignore rewrite using promises
.travis.yml just include bluebird
LICENSE rewrite using promises
README.md update package
index.js update package
package.json 2.0.2

README.md

Stream to Array

NPM version Build status Test coverage Dependency Status License Downloads Gittip

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

You may also be interested in:

API

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.

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.

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

})

If callback is not defined, then it is assumed that it is being yielded within a generator.

function* () {
  var stream = new Stream.Readable()
  stream.toArray = toArray
  var arr = yield stream.toArray()
}

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

var stream = new Stream.Readable()
var arr = yield toArray(stream)
var buffer = Buffer.concat(arr)
Something went wrong with that request. Please try again.