{"_id":"@cjser/get-stream__v8_0_1","name":"@cjser/get-stream__v8_0_1","dist-tags":{"latest":"8.0.1-cjser.2"},"versions":{"8.0.1-cjser.2":{"name":"@cjser/get-stream__v8_0_1","version":"8.0.1-cjser.2","description":"Get a stream as a string, Buffer, ArrayBuffer or array","license":"MIT","repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./source/index.d.ts","require":"./dist-cjser/index.cjs","default":"./source/index.js"},"engines":{"node":">=16"},"scripts":{"benchmark":"node benchmarks/index.js","test":"xo && ava && tsd --typings=source/index.d.ts --files=source/index.test-d.ts"},"keywords":["get","stream","promise","concat","string","text","buffer","read","data","consume","readable","readablestream","object","concat"],"devDependencies":{"@types/node":"^20.5.0","ava":"^5.3.1","precise-now":"^2.0.0","stream-json":"^1.8.0","tsd":"^0.28.1","xo":"^0.56.0"},"types":"./source/index.d.ts","main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"8.0.1","cjserVersion":2,"original":{"name":"get-stream","version":"8.0.1","exports":{"types":"./source/index.d.ts","default":"./source/index.js"},"repository":"sindresorhus/get-stream","files":["source","!*.test-d.ts"],"scripts":{"benchmark":"node benchmarks/index.js","test":"xo && ava && tsd --typings=source/index.d.ts --files=source/index.test-d.ts"}}},"_id":"@cjser/get-stream__v8_0_1@8.0.1-cjser.2","gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-ZnVzCK9hjG0j9pJGCnX0szx177/6y34yzUYgBzZksjaWlIXOqW8ll6HnzFF7vVBo2jkGzuhtNiShmFb96+MYMw==","shasum":"778f2d91ac2be6d9a087872a3250d93450014bc4","tarball":"https://registry.npmjs.org/@cjser/get-stream__v8_0_1/-/get-stream__v8_0_1-8.0.1-cjser.2.tgz","fileCount":12,"unpackedSize":35640,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIC0MJvVmPCcSWsXaacCz5KaelvgR4w4yLOlVDMdOWcmqAiAdENx98H/VrGsk75dMMJs/WKIO0TI6WWGKXrrOB1/dbw=="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"directories":{},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/get-stream__v8_0_1_8.0.1-cjser.2_1778158273307_0.39876121241134244"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T12:51:13.166Z","8.0.1-cjser.2":"2026-05-07T12:51:13.459Z","modified":"2026-05-07T12:51:13.718Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"Get a stream as a string, Buffer, ArrayBuffer or array","keywords":["get","stream","promise","concat","string","text","buffer","read","data","consume","readable","readablestream","object","concat"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","readme":"# get-stream\n\n> Get a stream as a string, Buffer, ArrayBuffer or array\n\n## Features\n\n- Works in any JavaScript environment ([Node.js](#nodejs-streams), [browsers](#web-streams), etc.).\n- Supports [text streams](#getstreamstream-options), [binary streams](#getstreamasbufferstream-options) and [object streams](#getstreamasarraystream-options).\n- Supports [async iterables](#async-iterables).\n- Can set a [maximum stream size](#maxbuffer).\n- Returns [partially read data](#errors) when the stream errors.\n- [Fast](#benchmarks).\n\n## Install\n\n```sh\nnpm install get-stream\n```\n\n## Usage\n\n### Node.js streams\n\n```js\nimport fs from 'node:fs';\nimport getStream from 'get-stream';\n\nconst stream = fs.createReadStream('unicorn.txt');\n\nconsole.log(await getStream(stream));\n/*\n              ,,))))))));,\n           __)))))))))))))),\n\\|/       -\\(((((''''((((((((.\n-*-==//////((''  .     `)))))),\n/|\\      ))| o    ;-.    '(((((                                  ,(,\n         ( `|    /  )    ;))))'                               ,_))^;(~\n            |   |   |   ,))((((_     _____------~~~-.        %,;(;(>';'~\n            o_);   ;    )))(((` ~---~  `::           \\      %%~~)(v;(`('~\n                  ;    ''''````         `:       `:::|\\,__,%%    );`'; ~\n                 |   _                )     /      `:|`----'     `-'\n           ______/\\/~    |                 /        /\n         /~;;.____/;;'  /          ___--,-(   `;;;/\n        / //  _;______;'------~~~~~    /;;/\\    /\n       //  | |                        / ;   \\;;,\\\n      (<_  | ;                      /',/-----'  _>\n       \\_| ||_                     //~;~~~~~~~~~\n           `\\_|                   (,~~\n                                   \\~\\\n                                    ~~\n*/\n```\n\n### Web streams\n\n```js\nimport getStream from 'get-stream';\n\nconst {body: readableStream} = await fetch('https://example.com');\nconsole.log(await getStream(readableStream));\n```\n\n### Async iterables\n\n```js\nimport {opendir} from 'node:fs/promises';\nimport {getStreamAsArray} from 'get-stream';\n\nconst asyncIterable = await opendir(directory);\nconsole.log(await getStreamAsArray(asyncIterable));\n```\n\n## API\n\nThe following methods read the stream's contents and return it as a promise.\n\n### getStream(stream, options?)\n\n`stream`: [`stream.Readable`](https://nodejs.org/api/stream.html#class-streamreadable), [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream), or [`AsyncIterable<string | Buffer | ArrayBuffer | DataView | TypedArray>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)\\\n`options`: [`Options`](#options)\n\nGet the given `stream` as a string.\n\n### getStreamAsBuffer(stream, options?)\n\nGet the given `stream` as a Node.js [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer).\n\n```js\nimport {getStreamAsBuffer} from 'get-stream';\n\nconst stream = fs.createReadStream('unicorn.png');\nconsole.log(await getStreamAsBuffer(stream));\n```\n\n### getStreamAsArrayBuffer(stream, options?)\n\nGet the given `stream` as an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).\n\n```js\nimport {getStreamAsArrayBuffer} from 'get-stream';\n\nconst {body: readableStream} = await fetch('https://example.com');\nconsole.log(await getStreamAsArrayBuffer(readableStream));\n```\n\n### getStreamAsArray(stream, options?)\n\nGet the given `stream` as an array. Unlike [other methods](#api), this supports [streams of objects](https://nodejs.org/api/stream.html#object-mode).\n\n```js\nimport {getStreamAsArray} from 'get-stream';\n\nconst {body: readableStream} = await fetch('https://example.com');\nconsole.log(await getStreamAsArray(readableStream));\n```\n\n#### options\n\nType: `object`\n\n##### maxBuffer\n\nType: `number`\\\nDefault: `Infinity`\n\nMaximum length of the stream. If exceeded, the promise will be rejected with a `MaxBufferError`.\n\nDepending on the [method](#api), the length is measured with [`string.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), [`buffer.length`](https://nodejs.org/api/buffer.html#buflength), [`arrayBuffer.byteLength`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength) or [`array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length).\n\n## Errors\n\nIf 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](#api).\n\n```js\nimport getStream from 'get-stream';\n\ntry {\n\tawait getStream(streamThatErrorsAtTheEnd('unicorn'));\n} catch (error) {\n\tconsole.log(error.bufferedData);\n\t//=> 'unicorn'\n}\n```\n\n## Tips\n\n### Alternatives\n\nIf you do not need the [`maxBuffer`](#maxbuffer) option, [`error.bufferedData`](#errors), nor browser support, you can use the following methods instead of this package.\n\n#### [`streamConsumers.text()`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream)\n\n```js\nimport fs from 'node:fs';\nimport {text} from 'node:stream/consumers';\n\nconst stream = fs.createReadStream('unicorn.txt', {encoding: 'utf8'});\nconsole.log(await text(stream))\n```\n\n#### [`streamConsumers.buffer()`](https://nodejs.org/api/webstreams.html#streamconsumersbufferstream)\n\n```js\nimport {buffer} from 'node:stream/consumers';\n\nconsole.log(await buffer(stream))\n```\n\n#### [`streamConsumers.arrayBuffer()`](https://nodejs.org/api/webstreams.html#streamconsumersarraybufferstream)\n\n```js\nimport {arrayBuffer} from 'node:stream/consumers';\n\nconsole.log(await arrayBuffer(stream))\n```\n\n#### [`readable.toArray()`](https://nodejs.org/api/stream.html#readabletoarrayoptions)\n\n```js\nconsole.log(await stream.toArray())\n```\n\n#### [`Array.fromAsync()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)\n\nIf your [environment supports it](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync#browser_compatibility):\n\n```js\nconsole.log(await Array.fromAsync(stream))\n```\n\n### Non-UTF-8 encoding\n\nWhen all of the following conditions apply:\n  - [`getStream()`](#getstreamstream-options) is used (as opposed to [`getStreamAsBuffer()`](#getstreamasbufferstream-options) or [`getStreamAsArrayBuffer()`](#getstreamasarraybufferstream-options))\n  - The stream is binary (not text)\n  - The stream's encoding is not UTF-8 (for example, it is UTF-16, hexadecimal, or Base64)\n\nThen the stream must be decoded using a transform stream like [`TextDecoderStream`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream) or [`b64`](https://github.com/hapijs/b64).\n\n```js\nimport getStream from 'get-stream';\n\nconst textDecoderStream = new TextDecoderStream('utf-16le');\nconst {body: readableStream} = await fetch('https://example.com');\nconsole.log(await getStream(readableStream.pipeThrough(textDecoderStream)));\n```\n\n### Blobs\n\n[`getStreamAsArrayBuffer()`](#getstreamasarraybufferstream-options) can be used to create [Blobs](https://developer.mozilla.org/en-US/docs/Web/API/Blob).\n\n```js\nimport {getStreamAsArrayBuffer} from 'get-stream';\n\nconst stream = fs.createReadStream('unicorn.txt');\nconsole.log(new Blob([await getStreamAsArrayBuffer(stream)]));\n```\n\n### JSON streaming\n\n[`getStreamAsArray()`](#getstreamasarraystream-options) can be combined with JSON streaming utilities to parse JSON incrementally.\n\n```js\nimport fs from 'node:fs';\nimport {compose as composeStreams} from 'node:stream';\nimport {getStreamAsArray} from 'get-stream';\nimport streamJson from 'stream-json';\nimport streamJsonArray from 'stream-json/streamers/StreamArray.js';\n\nconst stream = fs.createReadStream('big-array-of-objects.json');\nconsole.log(await getStreamAsArray(\n\tcomposeStreams(stream, streamJson.parser(), streamJsonArray.streamArray()),\n));\n```\n\n## Benchmarks\n\n### Node.js stream (100 MB, binary)\n\n- `getStream()`: 142ms\n- `text()`: 139ms\n- `getStreamAsBuffer()`: 106ms\n- `buffer()`: 83ms\n- `getStreamAsArrayBuffer()`: 105ms\n- `arrayBuffer()`: 81ms\n- `getStreamAsArray()`: 24ms\n- `stream.toArray()`: 21ms\n\n### Node.js stream (100 MB, text)\n\n- `getStream()`: 90ms\n- `text()`: 89ms\n- `getStreamAsBuffer()`: 127ms\n- `buffer()`: 192ms\n- `getStreamAsArrayBuffer()`: 129ms\n- `arrayBuffer()`: 195ms\n- `getStreamAsArray()`: 89ms\n- `stream.toArray()`: 90ms\n\n### Web ReadableStream (100 MB, binary)\n\n- `getStream()`: 223ms\n- `text()`: 221ms\n- `getStreamAsBuffer()`: 182ms\n- `buffer()`: 153ms\n- `getStreamAsArrayBuffer()`: 171ms\n- `arrayBuffer()`: 155ms\n- `getStreamAsArray()`: 83ms\n\n### Web ReadableStream (100 MB, text)\n\n- `getStream()`: 141ms\n- `text()`: 139ms\n- `getStreamAsBuffer()`: 91ms\n- `buffer()`: 80ms\n- `getStreamAsArrayBuffer()`: 89ms\n- `arrayBuffer()`: 81ms\n- `getStreamAsArray()`: 21ms\n\n[Benchmarks' source file](benchmarks/index.js).\n\n## FAQ\n\n### How is this different from [`concat-stream`](https://github.com/maxogden/concat-stream)?\n\nThis 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.\n\n## Related\n\n- [get-stdin](https://github.com/sindresorhus/get-stdin) - Get stdin as a string or buffer\n- [into-stream](https://github.com/sindresorhus/into-stream) - The opposite of this package\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/sindresorhus/get-stream\n","readmeFilename":"readme.md","_rev":"1-40937d5fda51969278ef81daed858503"}