0.0.1 • Published 10 years ago

easy-stream v0.0.1

Weekly downloads
3
License
-
Repository
-
Last release
10 years ago
make test
/*
Thin wrapper that makes setting up streams a bit easier.
Defaults to objectMode on read and write streams. You can 
override options by including a config.options object.
*/

var Easy = require("easy-stream");


//creates a read stream
var easyReadStream = Easy({
  _read: function() {
    var someData = {
      easy: "stream"
    };
    this.push(someData);
  },
  options: {}  //using default options.
});

//now create a corresponding writable stream with easy-stream.
var easyWriteStream = Easy({
  _write: function(obj, encoding, next) {
    //obj is the json object {easy: "stream"}
    console.log(obj);
    next();
  }
});

easyReadStream.pipe(easyWriteStream);

//creating a duplex stream is easy.
var stream = Easy({
  _write: function() {},
  _read: function() {}
});

//so is creating a transform stream
var stream = Easy({
  _transform: function() {}
  _flush: function() {}
});

//you can subclass any function too
function SomeFunction() {}
SomeFunction.prototype.someMethod = function() {};

var easyDuplexStream = Easy({
  _read: function() {},
  _write: function() {},
  createUsing: SomeFunction
})
0.0.1

10 years ago