ReadableStream of arrays, hashed variables [Node.js]
JavaScript
Switch branches/tags
Nothing to show
Latest commit 07be614 Mar 6, 2012 @shinout forEach()
Permalink
Failed to load latest commit information.
test forEach() Mar 7, 2012
ArrayStream.js forEach() Mar 7, 2012
LICENCE first commit Nov 16, 2011
README.md forEach() Mar 7, 2012
package.json forEach() Mar 7, 2012

README.md

ArrayStream.js 0.0.5

[Node.js] ReadableStream from array (or hash variable)

Overview

Installation

$ git clone git://github.com/shinout/ArrayStream.git

OR

$ npm install arraystream

Usage

with Array

var ArrayStream = require('arraystream');
var stream = ArrayStream.create(['hoge', 'fuga', 'piyo']);

stream.on('data', function(value, key) {
  console.log(value); // hoge, fuga, piyo
  console.log(key);   // 0,    1,    2
});

stream.on('end', function() { // emitted at the end of iteration
  console.log('end');
});

stream.on('error', function(e) { // emitted when an error occurred
  console.log(e);
});

with Object

var ArrayStream = require('arraystream');
var objstream = new ArrayStream({a:'hoge', b:'fuga', c:'piyo']);

objstream.on('data', function(value, key) {
  console.log(key);   // a,    b,    c
  console.log(value); // hoge, fuga, piyo
});

objstream.on('end', function() { // emitted at the end of Object
  console.log('end');
});

objstream.on('error', function(e) { // emitted when an error occurred
  console.log(e);
});

syntax sugar (forEach)

var arr = ['hoge', 'fuga', 'piyo'];
var stream = ArrayStream.forEach(arr, function(value, key) {
  console.log(value); // hoge, fuga, piyo
  console.log(key);   // 0,    1,    2
});

stream.on('end', function() { // emitted at the end of iteration
  console.log('end');
});

stream.on('error', function(e) { // emitted when an error occurred
  console.log(e);
});