1.0.0 • Published 5 years ago

@strong-roots-capital/stream-array v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

stream-array Build status npm version codecov

Pipe an array through a stream

Install

npm install @strong-roots-capital/stream-array

Use

import streamArray from '@strong-roots-capital/stream-array'
import { Writable } from 'readable-stream'

const array = [0, 1, 2, 3, 4, 5]

const sink = new Writable({
    objectMode: true,
    write(chunk: number, _: string, callback: (error?: Error | null) => void) {
        console.log(chunk)
        callback()
    }
})

sink.on('finish', () => console.log('fin'))
streamArray(array).pipe(sink)
//=>0
//=>1
//=>2
//=>3
//=>4
//=>5
//=>fin

Note that objectMode is true.

Related