Makes it easy to use various types of streams by giving a simple interfacing
and allowing specification of their actions by passing a function.
Use several types of streams (transform, read, write, counter) with minimal configuration or syntax. Just need input and functions to define transformations and output.
npm install @jadesrochers/streams
const streams = require('@jadesrochers/streams')
Four stream types are provided; read, transform, count, and write.
The count stream is just a custom transform stream for tracking
how many object passed through the stream.
let transfcn = n => (parseInt(n) + 1)
let writefcn = n => console.log(n) let reader = streams.fileStream('./testfile.txt')
let transform = streams.transformStream(transfcn)
let counter = streams.countStream(10, ' stream objects')
let writer = streams.writeStream(writefcn) const split = require('split2');testfile.txt; put it in the directory you will run node from.
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
reader.pipe(split()).pipe(transform).pipe(counter).pipe(writer).on('finish', () => { console.log('Stream complete, closed'); process.exit(0)}).on('error', () => console.log('Somthing went wrong'))