Skip to content

mscandal/co-stream-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is now not really needed as node streams are now async iterators

co-stream-iterator

This library gives you an easy way to process data coming from a stream linearly and synchronously using co or koa.

var co = require('co');
var request = require('request');
var iterator = require('co-stream-iterator');

co(function*() {
  var chunk, encoding;
  var read = iterator(request('http://google.com'), {});

  while (data = yield read) {
    console.log('data', data.encoding, data.chunk.toString());
  }
}).then(console.log);

It's even nicer looking when using destructuring:

while ({encoding, chunk} = yield read) {
  console.log('data', encoding, chunk.toString());
}

All you do is pass in your readable stream and your options for the writable stream it creates under the hood. This makes object streams possible to work with as well. The while loop ends when the data stops flowing. This is triggered by the generator returning null.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published