Compose a chain of Transform Streams with Express-like middleware.
npm install streaming-middleware
An instance of StreamingMiddleware is a type of Duplex Stream which internally writes data to and reads data from a chain of Transform streams that are piped through dynamically in the order you add them.
var StreamingMiddleware = require("streaming-middleware");
var app = StreamingMiddleware();
app
.use(function Uppercase(chunk, enc, next){
next(null, chunk.toString().toUpperCase() );
})
.use(function Reverse(chunk, enc, next){
next(null, chunk.toString().split("").reverse().join("").trim("") + "\n" );
})
process.stdin.pipe(app.stream()).pipe(process.stdout);
echo "pickle rick" | node app.js // # KCIR ELKCIP
npm test
# or
npm install -g mocha
mocha test/**/*spec.js --reporter spec
# or
mocha test/**/*spec.js --reporter=nyan
The test documentation was generated with Mocha’s “doc” reporter, and directly reflects the test suite.
npm run coverage
Transform stream builder
Add a Transform Function to the stack
Parameters
fn
Function An instanceof {Transform} or a plain Function with 3 args
Examples
Simple use
var app = StreamingMiddleware();
app.use(function Uppercase(chunk, enc, next){
next(null, chunk.toString().toUpperCase() );
})
Chaining
var app = StreamingMiddleware();
app
.use(function Uppercase(chunk, enc, next){
next(null, chunk.toString().toUpperCase() );
})
.use(function Reverse(chunk, enc, next){
next(null, chunk.toString().split("").reverse().join("").trim("") + "\n" );
})
Returns StreamingMiddleware
Return a Duplex stream built by connecting all the Transform streams which were added via StreamingMiddleware.use()
Parameters
options
Object options passed to each Transform e.g. "objectMode"
Examples
Stream of 2 Transforms in non object mode
var app = StreamingMiddleware();
app
.use(function Uppercase(chunk, enc, next){
next(null, chunk.toString().toUpperCase() );
})
.use(function Uppercase(chunk, enc, next){
next(null, chunk.toString().split("").reverse().join("").trim("") + "\n" );
})
process.stdin.pipe(app.stream()).pipe(process.stdout);
Returns DuplexStream
See more examples in the Example folder
- Experiment creating an easily extendable CLI for processing streamed data
- Experiment using a test driven approach
- Experiment using various Tools e.g. travis-ci, jshint, instanbul, autodoc etc