What is glob-stream?
The glob-stream npm package allows for reading file paths from a globbing pattern. It is a wrapper around node-glob and vinyl-fs to stream the file objects that match the glob patterns. This package is particularly useful in build processes and file manipulation scripts where matching files based on patterns is required.
What are glob-stream's main functionalities?
Reading files using glob patterns
This feature allows you to read files that match a specific pattern. In the code sample, all JavaScript files under the 'src' directory and its subdirectories are matched and their paths are logged.
const globStream = require('glob-stream');
const stream = globStream('./src/**/*.js');
stream.on('data', function(file) {
console.log(file.path);
});
Combining multiple glob patterns
glob-stream supports combining multiple patterns, including exclusion patterns. In this example, all JavaScript files under 'src' except those in the 'vendor' subdirectory are matched.
const globStream = require('glob-stream');
const stream = globStream(['./src/**/*.js', '!./src/vendor/**']);
stream.on('data', function(file) {
console.log(file.path);
});
Other packages similar to glob-stream
fast-glob
fast-glob is an alternative to glob-stream that provides a similar functionality of matching files based on glob patterns. It is known for its performance and offers a promise-based API, making it a good choice for modern asynchronous workflows. Unlike glob-stream, fast-glob does not return a stream of file objects but rather a promise that resolves with an array of matching paths.
node-glob
node-glob is the underlying library used by glob-stream for matching files based on patterns. While glob-stream provides a stream interface for handling the matched files, node-glob itself focuses on the globbing functionality and returns an array of matched file paths. It is a more basic option for those who do not need the streaming capabilities offered by glob-stream.
Information
Package | glob-stream |
Description | File system globs as a stream |
Node Version | >= 0.4 |
This is a simple wrapper around node-glob to make it streamy.
Usage
var gs = require('glob-stream');
var stream = gs.create("./files/**/*.coffee", {options - read node-glob docs});
stream.on('data', function(fileName){
# fileName == full path
});
LICENSE
(MIT License)
Copyright (c) 2013 Fractal contact@wearefractal.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.