Package Exports
- fast-stream-to-buffer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-stream-to-buffer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
fast-stream-to-buffer
Consume a stream of data into a binary Buffer as efficiently as possible.
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 streamcallback
- A callback function which will be called with an optional error object as the first argument and a buffer containing the content of thestream
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