cop - filter stream
Description
A through Stream
, configurable to emit specific properties of objects written to it. Furthermore, if provided with a filter function, cop
can be used to modulate data.
Usage
Property key
var cop = require('cop')
, es = require('event-stream')
, fstream = require('fstream')
, reader = fstream.Reader({ path:process.cwd() })
reader.pipe(cop('path')).pipe(es.writeArray(function (err, paths) {
console.log(paths)
}))
Filter function
var cop = require('cop')
, fstream = require('fstream')
, reader = fstream.Reader({ path:process.cwd() })
reader.pipe(cop(filter)).pipe(process.stdout)
function filter (obj) {
return obj ? obj['path'] + '\n' : undefined
}
Signature
cop(key)
Provided a key, cop
will emit the matching property of an object written to it. If the object has no matching property nothing is emitted.
cop(filter)
Alternatively a filter function can be provided, which is executed before data is emitted, hence, provides an opportunity to massage the data.
Events
See Stream
Installation
Install with npm:
npm install cop
License
MIT License