https://github.com/75lb/stream-read-all
Returns a promise which fulfils with the supplied stream's content
https://github.com/75lb/stream-read-all
nodejs stream
Last synced: 9 months ago
JSON representation
Returns a promise which fulfils with the supplied stream's content
- Host: GitHub
- URL: https://github.com/75lb/stream-read-all
- Owner: 75lb
- License: mit
- Created: 2017-06-18T09:01:43.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T00:39:57.000Z (over 1 year ago)
- Last Synced: 2025-02-02T08:31:51.756Z (over 1 year ago)
- Topics: nodejs, stream
- Language: JavaScript
- Homepage:
- Size: 87.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/stream-read-all)
[](https://www.npmjs.org/package/stream-read-all)
[](https://github.com/75lb/stream-read-all/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/stream-read-all/network/dependents?dependent_type=PACKAGE)
[](https://github.com/75lb/stream-read-all/actions/workflows/node.js.yml)
[](https://github.com/feross/standard)
# stream-read-all
Returns a promise which fulfils with the supplied stream's content. Supports any [Readable](https://nodejs.org/docs/latest/api/stream.html#readable-streams) stream as input in either regular or [object mode](https://nodejs.org/docs/latest/api/stream.html#object-mode).
For example, this script...
```js
import { streamReadAll } from 'stream-read-all'
const readable = await streamReadAll(process.stdin)
console.log(readable.toString())
```
...prints this output.
```
$ echo Hello | node example.js
Hello
```
The above `streamReadAll` function returns either a `Buffer` in regular mode or an array of objects in object mode. Alternatively, you can use `streamReadText` which is identical to the above except it returns text. The second argument is optional, specifying the character encoding to use (as in the [buffer.toString()](https://nodejs.org/docs/latest/api/buffer.html#buftostringencoding-start-end) first argument). The default value is 'utf8'.
```js
import { streamReadText } from 'stream-read-all'
const readable = fs.createReadStream('./package.json')
const text = await streamReadText(readable, 'hex')
console.log(text)
// prints the package.json file content in hex format
```
* * *
© 2017-25 Lloyd Brookes .