promisebuffer

1.0.0 • Public • Published

Promise Stream Buffer

Utilities for Buffering streamed content into a Promise value.

API

buffer(stream)

Given a stream returns a Promise that will resolve with the Buffered contents of to the Stream once it has been fully written (end event emitted).

Example:

var buffer = require('promisebuffer');
 
buffer(require('fs').createReadStream('myfile')).then(function(buffer) {
    console.log(buffer.toString());
}).catch(function(error) {
    console.error(error.message);
});

bufferStreamError(stream)

Given a stream buffer the first error that occurs until an event listener is registered. This allows you to attach event listeners in a different event loop run.

Example:

var bufferError = require('promisebuffer').bufferError;
 
var stream = bufferError(require('fs').createReadStream('myfile'));
 
// Allows you to attach error handlers inside async sections without an error
// throwing an uncaught exception
var x = new Promise(function(resolve, reject) {
    stream.on('error', reject);
    / * ... */
});

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i promisebuffer

Weekly Downloads

1

Version

1.0.0

License

none

Last publish

Collaborators

  • samgiles