es6-stream
streams reimagined to use generators
Last updated 3 years ago by cwmma .
ISC · Repository · Bugs · Original npm · Tarball
$ cnpm install es6-stream 
SYNC missed versions from official npm registry.

es6-stream

through streams with generators, inspired by this comment by @Qard. Requries harmony flags.

npm install es6-stream;

api


var splitStream = es6Stream(function * (read, write) {
    var chunk, i, len;
    while ((chunk = yield read())) {
      chunk = chunk.toString().split(' ');
      i = -1;
      len = chunk.length;
      while (++i < len) {
        yield write(chunk[i]);
      }
    }\
  })
var upcaseStream = es6Stream(function* (read, write) {
  var bytes = 1024
  var chunk
  while ((chunk = yield read(bytes))) {
    yield write(chunk.toString().toUpperCase())
  }
})

or use it for readable and writable streams

co(function *() {
	var read = es6Stream.read(readableStream);
	while ((chunk = yield read())) {
		//do something with chunk;
	}
});

co(function *() {
	var write = es6Stream.write(writableStream);
	var i = -1;
	var len = stuff.length;
	while (++i < len) {
		yield write(stuff[i]);
	}
});
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (4)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |