get-stream
Consume a Node.js or web stream into a string, Buffer, ArrayBuffer, or array
Repository Health
Technical Analysis
get-stream is a small utility by Sindre Sorhus that reads an entire Node.js stream, web ReadableStream, or async iterable into memory and resolves a Promise with the result — as a string, Buffer, ArrayBuffer, or array, depending on which export you use. It works identically in Node.js and browsers, supports a maxBuffer option to cap memory use, and returns partially-read data alongside the error if the stream fails midway, making it a common building block anywhere code needs to buffer a whole stream instead of processing it chunk by chunk.
What You Get
- A default export that reads a stream to a UTF-8 string, plus
getStreamAsBuffer,getStreamAsArrayBuffer, andgetStreamAsArrayvariants for binary and object streams - Consistent behavior across Node.js streams, web
ReadableStream, and async iterables - A
maxBufferoption to cap how much data is buffered before rejecting - Partially-read data attached to the error object when a stream errors mid-read, so callers don’t lose already-consumed data
Common Use Cases
- Reading an entire child process’s stdout/stderr into a string for logging or assertions
- Buffering an HTTP response body into a Buffer before parsing or hashing it
- Collecting an object-mode stream’s emitted items into a plain array for further processing
- Reading file or network streams in test fixtures where full-buffer comparison is simpler than streaming assertions
Under The Hood
Architecture - The shared engine lives in source/contents.js’s getStreamContents(), which normalizes any input (Node.js stream, web ReadableStream, or async iterable) into an async iterable via stream.js, then iterates chunks applying pluggable convertChunk/addChunk/getSize/truncateChunk strategies passed in by each format-specific entry point (string.js, buffer.js, array-buffer.js, array.js); a maxBuffer check in appendChunk truncates and throws MaxBufferError once the running size exceeds the limit, and on any error the partially-accumulated state is attached to the thrown error via normalizedError.bufferedData before rethrowing. Tech Stack - Pure ESM JavaScript ("type": "module") with two small runtime dependencies, @sec-ant/readable-stream (a cross-environment ReadableStream helper) and is-stream; linted with xo, tested with ava, and type-checked against source/index.d.ts via tsd. Code Quality - Format-specific test files (test/string.js, test/buffer.js, test/array.js, test/array-buffer.js) plus test/web-stream.js, test/browser.js, and test/integration.js give each output path and each stream source its own coverage, and the xo && ava && tsd test script combines linting, runtime tests, and type-definition tests in one gate. API Design - A single shared chunk-processing engine parameterized per output type keeps string.js/buffer.js/array.js each under ~40 lines, giving a small, consistent surface (getStream, getStreamAsBuffer, getStreamAsArrayBuffer, getStreamAsArray) that behaves the same whether the source is a Node stream, a web stream, or a plain async iterable.
Used by 3 apps in this directory
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
Amplication
Developer Tools · AI Code Assistants · Automation
Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.
LibreChat
Developer Tools · AI Assistants
Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.