Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
glob-stream
Advanced tools
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.
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);
});
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 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.
Readable streamx interface over anymatch.
var gs = require('glob-stream');
var readable = gs('./files/**/*.coffee', {
/* options */
});
var writable =
/* your WriteableStream */
readable.pipe(writable);
You can pass any combination of glob strings. One caveat is that you cannot only pass a negative glob, you must give it at least one positive glob so it knows where to start. If given a non-glob path (also referred to as a singular glob), only one file will be emitted. If given a singular glob and no files match, an error is emitted (see also options.allowEmpty
).
globStream(globs, [options])
Takes a glob string or an array of glob strings as the first argument and an options object as the second. Returns a stream of objects that contain cwd
, base
and path
properties.
options.allowEmpty
Whether or not to error upon an empty singular glob.
Type: Boolean
Default: false
(error upon no match)
options.dot
Whether or not to treat dotfiles as regular files. This is passed through to anymatch.
Type: Boolean
Default: false
options.cwd
The current working directory that the glob is resolved against.
Type: String
Default: process.cwd()
options.root
The root path that the glob is resolved against.
Type: String
Default: undefined
(use the filesystem root)
options.base
The absolute segment of the glob path that isn't a glob. This value is attached to each glob object and is useful for relative pathing.
Type: String
Default: The absolute path segement before a glob starts (see glob-parent)
options.cwdbase
Whether or not the cwd
and base
should be the same.
Type: Boolean
Default: false
options.uniqueBy
Filters stream to remove duplicates based on the string property name or the result of function. When using a function, the function receives the streamed data (objects containing cwd
, base
, path
properties) to compare against.
Type: String
or Function
Default: 'path'
Any glob-related options are documented in picomatch.
MIT
FAQs
Readable streamx interface over anymatch.
The npm package glob-stream receives a total of 2,244,700 weekly downloads. As such, glob-stream popularity was classified as popular.
We found that glob-stream demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.