@guanghechen/stream
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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)

Package Sidebar

Install

npm i @guanghechen/stream

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

32.2 kB

Total Files

6

Last publish

Collaborators

  • lemonclown