stream-api-pipe.js 618 B

12345678910111213141516171819
  1. var readdirp = require('..')
  2. , path = require('path')
  3. , through = require('through2')
  4. // print out all JavaScript files along with their size
  5. readdirp({ root: path.join(__dirname), fileFilter: '*.js' })
  6. .on('warn', function (err) { console.error('non-fatal error', err); })
  7. .on('error', function (err) { console.error('fatal error', err); })
  8. .pipe(through.obj(function (entry, _, cb) {
  9. this.push({ path: entry.path, size: entry.stat.size });
  10. cb();
  11. }))
  12. .pipe(through.obj(
  13. function (res, _, cb) {
  14. this.push(JSON.stringify(res) + '\n');
  15. cb();
  16. })
  17. )
  18. .pipe(process.stdout);