1.0.3 • Published 9 months ago
@guanghechen/stream v1.0.3
Utilities for handing node streams.
Install
npm
npm install --save @guanghechen/stream
yarn
yarn add @guanghechen/stream
Usage
Name | Description |
---|---|
concatStreams | Concatenate readable streams to async iterator. |
consumeStream | Consume readable stream. |
consumeStreams | Consume Consume multiple streams serially. |
mergeStreams | Merge multiple readable streams into one readable streams. |
stream2buffer | Consume read stream and encode the contents into buffer. |
Example
Basic.
import { consumeStreams } from '@guanghechen/stream' import fs from 'node:fs' const filepaths = ['a.txt', 'b.txt', 'c.txt'] const readers: NodeJS.ReadableStream[] = plainFilepaths.map(fp => fs.createReadStream(fp)) const writer: NodeJS.WritableStream = fs.createWriteStream('out.txt') await consumeStreams(readers, writer)
Middlewares, i.e., cipher data before output.
import { consumeStreams } from '@guanghechen/stream' import crypto from 'crypto' import fs from 'node:fs' const filepaths = ['a.txt', 'b.txt', 'c.txt'] const readers: NodeJS.ReadableStream[] = plainFilepaths.map(fp => fs.createReadStream(fp)) const writer: NodeJS.WritableStream = fs.createWriteStream('out.txt') const iv: Buffer = crypto.randomBytes(32) const key: Buffer = crypto.randomBytes(32) const cipher: crypto.Cipher = crypto.createCipheriv('aes-256-gcm', key, iv) await consumeStreams(readers, writer, cipher)
1.0.2
9 months ago
1.0.3
9 months ago
1.0.1
9 months ago
1.0.0
9 months ago
1.0.0-alpha.12
9 months ago
1.0.0-alpha.11
1 year ago
1.0.0-alpha.10
1 year ago
1.0.0-alpha.9
2 years ago
1.0.0-alpha.8
2 years ago
1.0.0-alpha.7
2 years ago
1.0.0-alpha.6
2 years ago
1.0.0-alpha.5
2 years ago
1.0.0-alpha.4
2 years ago
1.0.0-alpha.3
2 years ago
1.0.0-alpha.2
2 years ago
1.0.0-alpha.1
2 years ago