https://github.com/rousan/read-all
Read all data from a Readable stream with Promise
https://github.com/rousan/read-all
all buffer bytes node read readable stream
Last synced: 9 months ago
JSON representation
Read all data from a Readable stream with Promise
- Host: GitHub
- URL: https://github.com/rousan/read-all
- Owner: rousan
- License: mit
- Created: 2019-03-07T09:50:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-08T16:05:19.000Z (about 7 years ago)
- Last Synced: 2025-06-24T01:44:44.779Z (9 months ago)
- Topics: all, buffer, bytes, node, read, readable, stream
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/rousan/read-all)
[](https://codecov.io/gh/rousan/read-all)
[](https://www.npmjs.com/package/node-read-all)
[](https://www.npmjs.com/package/node-read-all)
[](https://github.com/rousan/read-all/graphs/contributors)
[](https://github.com/rousan/read-all/blob/master/LICENSE)
# read-all
Read all data from a Readable stream and get notified when Promise is resolved.
## Installation
Using npm:
```bash
$ npm install node-read-all
```
Using yarn:
```bash
$ yarn add node-read-all
```
## Usage
```javascript
const fs = require('fs');
const readAll = require('node-read-all');
const rStream = fs.createReadStream('file.txt');
rStream.setEncoding('utf8');
readAll(rStream)
.then(data => console.log(data))
.catch(console.error.bind(console));
```
When stream is in object mode:
```javascript
const { Transform } = require('stream');
const readAll = require('node-read-all');
const transformStream = new Transform({
readableObjectMode: true,
transform(chunk, encoding, callback) {
this.push({ value: chunk.toString() });
callback();
},
});
readAll(transformStream)
.then(data => console.log(data))
.catch(console.error.bind(console));
setTimeout(() => {
transformStream.write('a');
transformStream.write('b');
transformStream.write('c');
transformStream.end();
}, 1000);
```
## Contributing
Your PRs and stars are always welcome.