Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

57 Commits

Repository files navigation

Stream to Array

OBSOLETE: since node@18, there is now a stream.toArray() function

NPM versionBuild statusTest coverageDependency StatusLicenseDownloads

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

You may also be interested in:

API

vartoArray=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.

varstream=newStream.Readable()toArray(stream,function(err,arr){assert.ok(Array.isArray(arr))})

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

varstream=newStream.Readable()stream.toArray=toArraystream.toArray(function(err,arr){})

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

toArray(stream).then(function(parts){})

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

toArray(stream).then(function(parts){constbuffers=parts.map(part=>util.isBuffer(part) ? part : Buffer.from(part));returnBuffer.concat(buffers);})

About

[OBSOLETE] Concatenate a readable stream's data into a single array.

Resources

Stars

100 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages