Socket
Socket
Sign inDemoInstall

fast-stream-to-buffer

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fast-stream-to-buffer

Consume a stream of data into a binary Buffer as efficiently as possible


Version published
Maintainers
1
Install size
23.0 kB
Created

Readme

Source

fast-stream-to-buffer

Consume a stream of data into a binary Buffer as efficiently as possible.

Build status js-standard-style

Installation

npm install fast-stream-to-buffer --save

Usage

Process an abitrary readable stream:

const streamToBuffer = require('fast-stream-to-buffer')

streamToBuffer(stream, function (err, buf) {
  if (err) throw err
  console.log(buf.toString())
})

Or use the onStream() helper function:

const http = require('http')
const streamToBuffer = require('fast-stream-to-buffer')

// `http.get` expects a callback as the 2nd argument that will be called
// with a readable stream of the response
http.get('http://example.com', streamToBuffer.onStream(function (err, buf) {
  if (err) throw err
  console.log(buf.toString('utf8'))
})

API

streamToBuffer(stream, callback)

Arguments:

  • stream - Any readable stream
  • callback - A callback function which will be called with an optional error object as the first argument and a buffer containing the content of the stream as the 2nd

fn = streamToBuffer.onStream(callback)

Returns a function fn which expects a readable stream as its only argument. When called, it will automatically call streamToBuffer() with the stream as the first argument and the callback as the second.

License

MIT

Keywords

FAQs

Last updated on 21 Jun 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc