glob-filestream

0.3.2 • Public • Published

glob-filestream

Build Test Coverage Code Climate Downloads Version Dependency Status ISC License

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;
}

License

ISC

Readme

Keywords

none

Package Sidebar

Install

npm i glob-filestream

Weekly Downloads

0

Version

0.3.2

License

ISC

Unpacked Size

7.76 kB

Total Files

7

Last publish

Collaborators

  • kirilv