thru
transform stream sugar
Last updated 13 years ago by jessetane .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install thru 
SYNC missed versions from official npm registry.

thru

minimalist transform stream implementation

why

sugar for stream.Transform

how

var thru = require('thru');

var input = thru();

var inflate = thru(function(obj, cb) {
  if (obj === 'a') {
    this.push('a');
    this.push('b');
    cb();
  } else {
    cb(null, obj);
  }
});

var modify = thru(function(obj, cb) {
  if (obj === 'd') obj = 'c';
  cb(null, obj);
});

var deflate = thru(function(obj, cb) {
  if (obj === 'e') cb();
  else cb(null, obj);
});

var newlines = thru(function(obj, cb) {
  cb(null, obj + '\n');
});

input
  .pipe(inflate)
  .pipe(modify)
  .pipe(deflate)
  .pipe(newlines)
  .pipe(process.stdout);

newlines.on('end', function() {
  console.log('done!');
});

input.write('a'); // a
                  // b
input.write('d'); // c
input.write('e');
input.end();      // done!

inspiration

through
through2

license

WTFPL

Current Tags

  • 0.4.4                                ...           latest (24 days ago)

44 Versions

  • 0.4.4                                ...           24 days ago
  • 0.4.3                                ...           a month ago
  • 0.4.2                                ...           a month ago
  • 0.4.1                                ...           2 months ago
  • 0.4.0                                ...           2 months ago
  • 0.3.18                                ...           2 months ago
  • 0.3.17                                ...           2 months ago
  • 0.3.16                                ...           3 months ago
  • 0.3.15                                ...           3 months ago
  • 0.3.14                                ...           3 months ago
  • 0.3.13                                ...           3 months ago
  • 0.3.12                                ...           3 months ago
  • 0.3.11                                ...           3 months ago
  • 0.3.10                                ...           3 months ago
  • 0.3.9                                ...           3 months ago
  • 0.3.8                                ...           3 months ago
  • 0.3.7                                ...           3 months ago
  • 0.3.6                                ...           3 months ago
  • 0.3.5                                ...           3 months ago
  • 0.3.4                                ...           4 months ago
  • 0.3.3                                ...           4 months ago
  • 0.3.2                                ...           4 months ago
  • 0.3.1                                ...           4 months ago
  • 0.3.0                                ...           4 months ago
  • 0.2.40                                ...           4 months ago
  • 0.2.39                                ...           4 months ago
  • 0.2.38                                ...           5 months ago
  • 0.2.37                                ...           5 months ago
  • 0.2.36                                ...           5 months ago
  • 0.2.35                                ...           5 months ago
  • 0.2.34                                ...           5 months ago
  • 0.2.33                                ...           5 months ago
  • 0.2.32                                ...           5 months ago
  • 0.2.31                                ...           5 months ago
  • 0.2.30                                ...           5 months ago
  • 0.2.29                                ...           5 months ago
  • 0.2.28                                ...           5 months ago
  • 0.2.27                                ...           6 months ago
  • 0.2.26                                ...           6 months ago
  • 0.2.24                                ...           6 months ago
  • 0.2.23                                ...           6 months ago
  • 0.0.3                                ...           7 months ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
Maintainers (1)
Downloads
Total 134
Today 0
This Week 1
This Month 131
Last Day 0
Last Week 50
Last Month 1
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE