Gathering detailed insights and metrics for get-stream
Gathering detailed insights and metrics for get-stream
Gathering detailed insights and metrics for get-stream
Gathering detailed insights and metrics for get-stream
npm install get-stream
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (91.31%)
TypeScript (8.69%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
349 Stars
124 Commits
30 Forks
10 Watchers
1 Branches
17 Contributors
Updated on Jun 25, 2025
Latest Version
9.0.1
Package Id
get-stream@9.0.1
Unpacked Size
27.69 kB
Size
7.89 kB
File Count
13
NPM Version
9.2.0
Node Version
20.11.1
Published on
Mar 16, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
7
Get a stream as a string, Buffer, ArrayBuffer or array
1npm install get-stream
1import fs from 'node:fs'; 2import getStream from 'get-stream'; 3 4const stream = fs.createReadStream('unicorn.txt'); 5 6console.log(await getStream(stream)); 7/* 8 ,,))))))));, 9 __)))))))))))))), 10\|/ -\(((((''''((((((((. 11-*-==//////(('' . `)))))), 12/|\ ))| o ;-. '((((( ,(, 13 ( `| / ) ;))))' ,_))^;(~ 14 | | | ,))((((_ _____------~~~-. %,;(;(>';'~ 15 o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~ 16 ; ''''```` `: `:::|\,__,%% );`'; ~ 17 | _ ) / `:|`----' `-' 18 ______/\/~ | / / 19 /~;;.____/;;' / ___--,-( `;;;/ 20 / // _;______;'------~~~~~ /;;/\ / 21 // | | / ; \;;,\ 22 (<_ | ; /',/-----' _> 23 \_| ||_ //~;~~~~~~~~~ 24 `\_| (,~~ 25 \~\ 26 ~~ 27*/
1import getStream from 'get-stream'; 2 3const {body: readableStream} = await fetch('https://example.com'); 4console.log(await getStream(readableStream));
This works in any browser, even the ones not supporting ReadableStream.values()
yet.
1import {opendir} from 'node:fs/promises'; 2import {getStreamAsArray} from 'get-stream'; 3 4const asyncIterable = await opendir(directory); 5console.log(await getStreamAsArray(asyncIterable));
The following methods read the stream's contents and return it as a promise.
stream
: stream.Readable
, ReadableStream
, or AsyncIterable<string | Buffer | ArrayBuffer | DataView | TypedArray>
options
: Options
Get the given stream
as a string.
Get the given stream
as a Node.js Buffer
.
1import {getStreamAsBuffer} from 'get-stream'; 2 3const stream = fs.createReadStream('unicorn.png'); 4console.log(await getStreamAsBuffer(stream));
Get the given stream
as an ArrayBuffer
.
1import {getStreamAsArrayBuffer} from 'get-stream'; 2 3const {body: readableStream} = await fetch('https://example.com'); 4console.log(await getStreamAsArrayBuffer(readableStream));
Get the given stream
as an array. Unlike other methods, this supports streams of objects.
1import {getStreamAsArray} from 'get-stream'; 2 3const {body: readableStream} = await fetch('https://example.com'); 4console.log(await getStreamAsArray(readableStream));
Type: object
Type: number
Default: Infinity
Maximum length of the stream. If exceeded, the promise will be rejected with a MaxBufferError
.
Depending on the method, the length is measured with string.length
, buffer.length
, arrayBuffer.byteLength
or array.length
.
If the stream errors, the returned promise will be rejected with the error
. Any contents already read from the stream will be set to error.bufferedData
, which is a string
, a Buffer
, an ArrayBuffer
or an array depending on the method used.
1import getStream from 'get-stream'; 2 3try { 4 await getStream(streamThatErrorsAtTheEnd('unicorn')); 5} catch (error) { 6 console.log(error.bufferedData); 7 //=> 'unicorn' 8}
For this module to work in browsers, a bundler must be used that either:
exports.browser
field in package.json
node:*
importsMost bundlers (such as Webpack) support either of these.
Additionally, browsers support web streams and async iterables, but not Node.js streams.
If you do not need the maxBuffer
option, error.bufferedData
, nor browser support, you can use the following methods instead of this package.
streamConsumers.text()
1import fs from 'node:fs'; 2import {text} from 'node:stream/consumers'; 3 4const stream = fs.createReadStream('unicorn.txt', {encoding: 'utf8'}); 5console.log(await text(stream))
streamConsumers.buffer()
1import {buffer} from 'node:stream/consumers'; 2 3console.log(await buffer(stream))
streamConsumers.arrayBuffer()
1import {arrayBuffer} from 'node:stream/consumers'; 2 3console.log(await arrayBuffer(stream))
readable.toArray()
1console.log(await stream.toArray())
Array.fromAsync()
If your environment supports it:
1console.log(await Array.fromAsync(stream))
When all of the following conditions apply:
getStream()
is used (as opposed to getStreamAsBuffer()
or getStreamAsArrayBuffer()
)Then the stream must be decoded using a transform stream like TextDecoderStream
or b64
.
1import getStream from 'get-stream'; 2 3const textDecoderStream = new TextDecoderStream('utf-16le'); 4const {body: readableStream} = await fetch('https://example.com'); 5console.log(await getStream(readableStream.pipeThrough(textDecoderStream)));
getStreamAsArrayBuffer()
can be used to create Blobs.
1import {getStreamAsArrayBuffer} from 'get-stream'; 2 3const stream = fs.createReadStream('unicorn.txt'); 4console.log(new Blob([await getStreamAsArrayBuffer(stream)]));
getStreamAsArray()
can be combined with JSON streaming utilities to parse JSON incrementally.
1import fs from 'node:fs'; 2import {compose as composeStreams} from 'node:stream'; 3import {getStreamAsArray} from 'get-stream'; 4import streamJson from 'stream-json'; 5import streamJsonArray from 'stream-json/streamers/StreamArray.js'; 6 7const stream = fs.createReadStream('big-array-of-objects.json'); 8console.log(await getStreamAsArray( 9 composeStreams(stream, streamJson.parser(), streamJsonArray.streamArray()), 10));
getStream()
: 142mstext()
: 139msgetStreamAsBuffer()
: 106msbuffer()
: 83msgetStreamAsArrayBuffer()
: 105msarrayBuffer()
: 81msgetStreamAsArray()
: 24msstream.toArray()
: 21msgetStream()
: 90mstext()
: 89msgetStreamAsBuffer()
: 127msbuffer()
: 192msgetStreamAsArrayBuffer()
: 129msarrayBuffer()
: 195msgetStreamAsArray()
: 89msstream.toArray()
: 90msgetStream()
: 223mstext()
: 221msgetStreamAsBuffer()
: 182msbuffer()
: 153msgetStreamAsArrayBuffer()
: 171msarrayBuffer()
: 155msgetStreamAsArray()
: 83msgetStream()
: 141mstext()
: 139msgetStreamAsBuffer()
: 91msbuffer()
: 80msgetStreamAsArrayBuffer()
: 89msarrayBuffer()
: 81msgetStreamAsArray()
: 21msconcat-stream
?This module 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, Buffer
, an ArrayBuffer
or an array. It doesn't have a fragile type inference. You explicitly choose what you want. And it doesn't depend on the huge readable-stream
package.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 24/30 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More