You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

stream-to-array

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-to-array

Concatenate a readable stream's data into a single array


Version published
Weekly downloads
1.2M
decreased by-6.01%
Maintainers
2
Install size
29.0 kB
Created
Weekly downloads
 

Package description

What is stream-to-array?

The stream-to-array npm package is a utility that allows you to collect all the data from a stream into an array. This can be particularly useful when you need to process the entire content of a stream at once, rather than handling it piece by piece.

What are stream-to-array's main functionalities?

Convert Stream to Array

This feature allows you to convert a readable stream into an array. The example demonstrates creating a readable stream, pushing data into it, and then converting the stream into an array using the stream-to-array package.

const streamToArray = require('stream-to-array');
const { Readable } = require('stream');

const readable = new Readable({
  read() {}
});

readable.push('data1');
readable.push('data2');
readable.push(null);

streamToArray(readable, (err, arr) => {
  if (err) throw err;
  console.log(arr); // ['data1', 'data2']
});

Other packages similar to stream-to-array

Readme

Source

Stream to Array

NPM version Build status Test coverage Dependency Status License Downloads

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

You may also be interested in:

  • raw-body for strings

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 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) {
    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)
  })

Keywords

FAQs

Package last updated on 28 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc