1.1.0 • Published 8 years ago

co-transform v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

co-transform

stream.Transform with generator NPM #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);
1.1.0

8 years ago

1.0.0

8 years ago