heroku-debug
Version:
debugging plugin for the CLI
84 lines (54 loc) • 2.45 kB
Markdown
> Get a stream as a string or buffer
```
$ npm install --save get-stream
```
```js
const fs = require('fs');
const getStream = require('get-stream');
const stream = fs.createReadStream('unicorn.txt');
getStream(stream).then(str => {
console.log(str);
/*
,,))))))));,
__)))))))))))))),
\|/ -\(((((''''((((((((.
-*-==//////(('' . `)))))),
/|\ ))| o ;-. '((((( ,(,
( `| / ) ;))))' ,_))^;(~
| | | ,))((((_ _____------~~~-. %,;(;(>';'~
o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~
; ''''```` `: `:::|\,__,%% );`'; ~
| _ ) / `:|`----' `-'
______/\/~ | / /
/~;;.____/;;' / ___--,-( `;;;/
/ // _;______;'------~~~~~ /;;/\ /
// | | / ; \;;,\
(<_ | ; /',/-----' _>
\_| ||_ //~;~~~~~~~~~
`\_| (,~~
\~\
~~
*/
});
```
Both methods returns a promise that is resolved when the `end` event fires on the stream, indicating that there is no more data to be read.
Get the stream as a string.
Type: `string`
Default: `utf8`
[](https://nodejs.org/api/buffer.html#buffer_buffer) of the incoming stream.
Get the stream as a buffer.
This one accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string or buffer. It doesn't have a fragile type inference. You explicitly choose what you want. It supports back-pressure and it doesn't depend on the huge `readable-stream` package.
- [get-stdin](https://github.com/sindresorhus/get-stdin) - Get stdin as a string or buffer
MIT © [Sindre Sorhus](http://sindresorhus.com)