Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/then/sprom
Convert node.js Streams into Promises
https://github.com/then/sprom
Last synced: about 2 months ago
JSON representation
Convert node.js Streams into Promises
- Host: GitHub
- URL: https://github.com/then/sprom
- Owner: then
- Created: 2013-04-23T21:16:51.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-11-16T02:36:27.000Z (over 6 years ago)
- Last Synced: 2024-04-14T23:02:36.967Z (2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 14
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Lists
- awesome-promises - sprom - Resolve when a stream ends. Optional buffering (be careful with this!) (Convenience Utilities / Others)
README
# sprom
Convert node.js Streams into Promises
[![Build Status](https://img.shields.io/travis/then/sprom/master.svg)](https://travis-ci.org/then/sprom)
[![Dependency Status](https://img.shields.io/david/then/sprom.svg)](https://david-dm.org/then/sprom)## Installation
$ npm install sprom
## Usage
```javascript
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