co-transform

1.1.0 • Public • Published

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);
 

Readme

Keywords

Package Sidebar

Install

npm i co-transform

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • hiroqn