Skip to content

Commit

Permalink
Clean up readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bendrucker committed Jun 18, 2016
1 parent 93a305e commit dae1d7d
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
stream-to-promise [![Build Status](https://travis-ci.org/bendrucker/stream-to-promise.svg)](https://travis-ci.org/bendrucker/stream-to-promise) [![NPM version](https://badge.fury.io/js/stream-to-promise.svg)](http://badge.fury.io/js/stream-to-promise)
stream-to-promise [![Build Status](https://travis-ci.org/bendrucker/stream-to-promise.svg)](https://travis-ci.org/bendrucker/stream-to-promise)
=================

Convert streams (readable or writable) to promises
> Convert streams (readable or writable) to promises
## Installing

```sh
$ npm install --save[-dev] stream-to-promise
```

## Examples

### Readable Streams

```js
streamToPromise(readableStream).then(function (buffer) {
// buffer.length === 3
});
readableStream.emit('data', new Buffer());
readableStream.emit('data', new Buffer());
readableStream.emit('data', new Buffer());
readableStream.emit('end'); // promise is resolved here
})
readableStream.emit('data', new Buffer())
readableStream.emit('data', new Buffer())
readableStream.emit('data', new Buffer())
readableStream.emit('end') // promise is resolved here
```

### Writable Streams

```js
streamToPromise(writableStream).then(function () {
// resolves undefined
});
writableStream.write('data');
writeableStream.end(); // promise is resolved here
})
writableStream.write('data')
writeableStream.end() // promise is resolved here
```

### Error Handling

```js
var err = new Error();
var err = new Error()
streamToPromise(stream).catch(function (error) {
// error === err;
});
stream.emit('error', err); // promise is rejected here
// error === err
})
stream.emit('error', err) // promise is rejected here
```

0 comments on commit dae1d7d

Please sign in to comment.