get-stream
- Version 9.0.1
- Published
- 28.4 kB
- 2 dependencies
- MIT license
Install
npm i get-stream
yarn add get-stream
pnpm add get-stream
Overview
Get a stream as a string, Buffer, ArrayBuffer or array
Index
Functions
function getStream
getStream: (stream: AnyStream, options?: Options) => Promise<string>;
Get the given
stream
as a string.Returns
The stream's contents as a promise.
Example 1
import fs from 'node:fs';import getStream from 'get-stream';const stream = fs.createReadStream('unicorn.txt');console.log(await getStream(stream));// ,,))))))));,// __)))))))))))))),// \|/ -\(((((''''((((((((.// -*-==//////(('' . `)))))),// /|\ ))| o ;-. '((((( ,(,// ( `| / ) ;))))' ,_))^;(~// | | | ,))((((_ _____------~~~-. %,;(;(>';'~// o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~// ; ''''```` `: `:::|\,__,%% );`'; ~// | _ ) / `:|`----' `-'// ______/\/~ | / /// /~;;.____/;;' / ___--,-( `;;;/// / // _;______;'------~~~~~ /;;/\ /// // | | / ; \;;,\// (<_ | ; /',/-----' _>// \_| ||_ //~;~~~~~~~~~// `\_| (,~~// \~\// ~~Example 2
import getStream from 'get-stream';const {body: readableStream} = await fetch('https://example.com');console.log(await getStream(readableStream));Example 3
import {opendir} from 'node:fs/promises';import {getStreamAsArray} from 'get-stream';const asyncIterable = await opendir(directory);console.log(await getStreamAsArray(asyncIterable));
function getStreamAsArray
getStreamAsArray: <Item>( stream: AnyStream<Item>, options?: Options) => Promise<Item[]>;
Get the given
stream
as an array. Unlike [other methods](#api), this supports [streams of objects](https://nodejs.org/api/stream.html#object-mode).Returns
The stream's contents as a promise.
Example 1
import {getStreamAsArray} from 'get-stream';const {body: readableStream} = await fetch('https://example.com');console.log(await getStreamAsArray(readableStream));
function getStreamAsArrayBuffer
getStreamAsArrayBuffer: ( stream: AnyStream, options?: Options) => Promise<ArrayBuffer>;
Get the given
stream
as an [ArrayBuffer
](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).Returns
The stream's contents as a promise.
Example 1
import {getStreamAsArrayBuffer} from 'get-stream';const {body: readableStream} = await fetch('https://example.com');console.log(await getStreamAsArrayBuffer(readableStream));
function getStreamAsBuffer
getStreamAsBuffer: (stream: AnyStream, options?: Options) => Promise<Buffer>;
Get the given
stream
as a Node.js [Buffer
](https://nodejs.org/api/buffer.html#class-buffer).Returns
The stream's contents as a promise.
Example 1
import {getStreamAsBuffer} from 'get-stream';const stream = fs.createReadStream('unicorn.png');console.log(await getStreamAsBuffer(stream));
Classes
class MaxBufferError
class MaxBufferError extends Error {}
constructor
constructor();
property name
readonly name: string;
Type Aliases
type AnyStream
type AnyStream<SteamItem = TextStreamItem> = | Readable | ReadableStream<SteamItem> | AsyncIterable<SteamItem>;
type Options
type Options = { /** Maximum length of the stream. If exceeded, the promise will be rejected with a `MaxBufferError`.
Depending 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).
@default Infinity */ readonly maxBuffer?: number;};
type TextStreamItem
type TextStreamItem = string | Buffer | ArrayBuffer | ArrayBufferView;
Package Files (1)
Dependencies (2)
Dev Dependencies (7)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/get-stream
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/get-stream)
- HTML<a href="https://www.jsdocs.io/package/get-stream"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3699 ms. - Missing or incorrect documentation? Open an issue for this package.