glob-filestream
v0.3.2
Published
Reads a glob of files into a single stream
Downloads
4,510
Readme
glob-filestream
Reads a glob of files into a single stream.
Install
npm install --save glob-filestream
Usage
Pass in a glob or array of globs, and get all of the matched content in one stream.
var globfile = require('glob-filestream');
var stream = globfile('*.txt');
// read like a regular filestream
var data = [];
stream.on('data', function(chunk) {
data.push(chunk);
});
stream.on('end', function() {
console.log(Buffer.concat(data).toString());
});
Files will be read and piped as-is, but sometimes, you may want to separate individual files with a new line. You can use the options for that, as such:
var stream = globfile('*.txt', {
appendNewLine: true
});
Every once in a while, you might find the need to transform individual files as you read them. There is an option for that as well.
var globfile = require('glob-filestream');
var ensureGunzip = require('ensure-gunzip');
var stream = globfile(['*.txt.gzip', '*.txt'], {
transform: ensureGunzip
});
// read `stream`, containing all plain text files
Transform is a function that takes a stream
as a parameter and returns a new stream. The identify transform function would look like this:
function transform(stream) {
return stream;
}