get-stream
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
pump | 3.0.0 | 3.16 kB | MIT | prod |
The "get-stream" npm package is designed to convert streams into strings, buffers, array buffers, or arrays in the JavaScript environment. It's compatible with Node.js, browsers, and enables various stream types including text streams, binary streams, and object streams. The package also facilitates async iterables usage, allows assigning a maximum stream size, swiftly returns partially read data when an error occurs in the stream, and is quite efficient in terms of its performance.
To use "get-stream", you'll need to first install the package using npm by running npm install get-stream
. Once installed, you can utilize it in your JavaScript code. It has various methods to get a readable stream and convert it to the respective format.
For instance, to read a Node.js Stream, you might use this code:
import fs from 'node:fs';
import getStream from 'get-stream';
const stream = fs.createReadStream('unicorn.txt');
console.log(await getStream(stream));
If your scenario involves reading a Web Stream, you would use this different approach:
import getStream from 'get-stream';
const {body: readableStream} = await fetch('https://example.com');
console.log(await getStream(readableStream));
For Async Iterables, it could be something like this:
import {opendir} from 'node:fs/promises';
import {getStreamAsArray} from 'get-stream';
const asyncIterable = await opendir(directory);
console.log(await getStreamAsArray(asyncIterable));
These are just a few of the many examples of using "get-stream" in various different scenarios.
The documentation for "get-stream" can be found in the README file in the official GitHub repository. The README contains a comprehensive guide on how to use this npm package, its methods, as well as error handling and other tips.