Last active
August 3, 2018 11:44
-
-
Save thibauts/5b92c7d4f367b8deefde to your computer and use it in GitHub Desktop.
Takes a stream of filenames on stdin and outputs the file contents on stdout each time a new filename is pushed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Takes a stream of filenames on stdin and outputs | |
* the file contents on stdout each time a new filename is pushed. | |
*/ | |
var _ = require('highland'); | |
var fs = require('fs'); | |
function foo(filename) { | |
return _(fs.createReadStream(filename)); // `sequence()` expects an highland stream so let's wrap | |
} | |
/* | |
* We first split on line breaks, then map each filename to a stream of the file contents. | |
* `sequence()` expects a stream of streams and concatenates it in a single output stream so we're fine :) | |
* See http://highlandjs.org/#sequence | |
*/ | |
_(process.stdin).split().map(foo).sequence().pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment