co-transform
v1.1.0
Published
stream.Transform with generator
Downloads
1
Readme
co-transform
stream.Transform with generator #Usage
transform(generator, options)
generator
transform(function* () {
this instanceof require('stream').Transform;
let chunk = yield; // you yield and get value
throw new Error('SomeError') // and you can throw error = error event emit
return // you can return = end event emit
})
options
is stream.Transform options,
so, stream.Readable options and
stream.Writable options
#example
##String
const transform = require('co-transform');
process.stdin
.setEncoding('utf8')
.pipe(transform(function* () {
let chunk;
while(chunk = yield) {
this.push(chunk.toUpperCase());
}
}, {decodeStrings: false}))
.pipe(process.stdout);
##Object
objectStream
.pipe(transform(function* () {
let obj;
while(obj = yield) {
this.push(obj);
}
}, {objectMode: true}))
.pipe(distStream);