
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
streamfilter
Advanced tools
Filtering streams.
streamfilter
is a function based filter for streams inspired per gulp-filter
but no limited to Gulp nor to objectMode streams.
First, install streamfilter
in your project:
npm install --save streamfilter
There are 3 common usages:
import { StreamFilter } from 'streamfilter';
const filter = new StreamFilter((chunk, encoding, cb) => {
const mustBeFiltered = chunk.length() > 128;
if (mustBeFiltered) {
cb(true);
return;
}
cb(false);
});
// Print to stdout a filtered stdin
process.stdin.pipe(filter).pipe(process.stdout);
import { filterStream } from 'streamfilter';
// Here we use the functionnal help
const filter = new filterStream(
// Here we use an async callback instead
async (chunk, encoding) => {
const mustBeFiltered = chunk.length() > 128;
if (mustBeFiltered) {
return true;
}
return false;
},
{
restore: true,
},
);
// Print accepted chunks in stdout
filter.pipe(process.stdout);
// Print filtered one to stderr
filter.restore.pipe(process.stderr);
Let's reach total hype!
import { StreamFilter } from 'streamfilter';
import { Transform } from 'stream';
// Filter values
const filter = new StreamFilter(
(chunk, encoding, cb) => {
const mustBeFiltered = chunk.length() > 128;
if (mustBeFiltered) {
cb(true);
return;
}
cb(false);
},
{
restore: true,
passthrough: true,
},
);
// Uppercase strings
const mySuperTransformStream = new Transform({
transform: (chunk, encoding, cb) =>
cb(null, Buffer.from(chunk.toString(encoding).toUpperCase(), encoding)),
});
// Pipe stdin
process.stdin
.pipe(filter)
// Edit kept chunks
.pipe(mySuperTransformStream)
// Restore filtered chunks
.pipe(filter.restore)
// and output!
.pipe(process.stdout);
Note that in this case, this is your responsibility to end the restore stream by piping in another stream or ending it manually.
Filter piped in streams according to the given filterCallback
.
Utility function if you prefer a functional way of using this lib
Filter piped in streams according to the given filterCallback
.
Options are passed in as is in the various stream instances spawned by this
module. So, to use the objectMode, simply pass in the options.objectMode
value set to true
.
Returns: StreamFilter
- The filtering stream
Param | Type | Description |
---|---|---|
filterCallback | function | Callback applying the filters |
options | Object | Filtering options |
options.passthrough | boolean | Set to true , this option changes the restore stream nature from a readable stream to a passthrough one, allowing you to reuse the filtered chunks in an existing pipeline. |
options.restore | boolean | Set to true , this option create a readable stream allowing you to use the filtered chunks elsewhere. The restore stream is exposed in the FilterStream instance as a restore named property. |
Utility function if you prefer a functional way of using this lib
Kind: global function
Returns: Stream
Param |
---|
filterCallback |
options |
FAQs
Filtering streams.
The npm package streamfilter receives a total of 136,209 weekly downloads. As such, streamfilter popularity was classified as popular.
We found that streamfilter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.