1.0.11 • Published 4 years ago

stream-workflow v1.0.11

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

StreamFlow

Encapsulate streams for use in object-oriented programming.

NPM Build Status Coverage Status NPM Download Dependencies Status

Replace transform stream

Transform stream

const StreamFlow = require("stream-workflow");
const { Transform, pipeline } = require("stream");
const JSONStream = require("JSONStream");
const fs = require("fs");

fs.createReadStream(`data.json`)
    .pipe(JSONStream.parse("*"))
    .pipe(new Transform({
        objectMode: true,
        transform(chunk, enc, cb) {
            cb(null, chunk);
        }
    }));

by stream-workflow

StreamWorkflow

class CustomStream extends StreamFlow { {
    constructor({
        objectMode: true,
        init(stream) {              // init function must return the last stream of the pipeline.
            return pipeline(        
                stream,             // pathtrought stream
                JSONStream.parse(), // Transform 1 in diagram
                new Transform({     // Transform 2 in diagram
                    objectMode: true,
                    transform(chunk, enc, cb) {
                        cb(null, chunk);
                    }
                }),
                error => error && this.emit("error", error)
            )
        }
    })
}

fs.createReadStream(`data.json`)
    .pipe(new CustomStream());

Test

To run our tests, clone the stream-workflow repo and install the dependencies.

$ git clone https://github.com/BenoitClaveau/stream-workflow --depth 1
$ cd stream-workflow
$ npm install
$ cd tests
$ node.exe "../node_modules/mocha/bin/mocha" .
1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago