Skip to content

then/sprom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b83d106 · Nov 16, 2017

History

23 Commits
Apr 23, 2013
May 3, 2014
Nov 16, 2017
Dec 23, 2015
May 6, 2014
Nov 16, 2017
May 6, 2014

Repository files navigation

sprom

Convert node.js Streams into Promises

Build Status Dependency Status

Installation

$ npm install sprom

Usage

sprom.end(request(url).pipe(fs.createWriteStream('file.json')))
  .then(function () {
    console.log('Successfully wrote file');
  }, function (err) {
    console.error('Failed to write file');
    console.error(err.stack || err.message || err);
  });
sprom(request(url))
  .then(function (body) {
    console.dir(JSON.parse(body.toString()));
  })
  .then(null, function (err) {
    console.error('Failed to read JSON');
    console.error(err.stack || err.message || err);
  });

API

sprom.end(stream)

Get a promise that is resolved when the stream has ended. This won't make any attempt to look at the data of the stream.

sprom.buf(stream)

Buffers the contents of the stream using concat-stream and returns a promise for the concatenated results.

sprom.arr(stream)

Buffers the contents of the stream into an array and returns a promise for the array.

License

MIT