Skip to content

Commit

Permalink
stream map example
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday authored and polotek committed Aug 12, 2012
1 parent 82a57ec commit 3ddd4a0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/stream_map.js
@@ -0,0 +1,23 @@
var $p = require('../');
var Stream = require('stream').Stream;

var grepEven = new Stream;
grepEven.readable = true;
grepEven.writable = true;

var data = '';
grepEven.write = function (buf) { data += buf };
grepEven.end = function () {
this.emit('data', data
.split('\n')
.map(function (line) { return line + '\n' })
.filter(function (line) { return line.match(/even/) })
.join('')
);
this.emit('end');
};

$p('cat ../tests/fixtures/10lines.txt')
.pipe(grepEven)
.pipe('wc -l')
.pipe(process.stdout);

0 comments on commit 3ddd4a0

Please sign in to comment.