Socket
Book a DemoInstallSign in
Socket

filter2

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter2

A versatile stream filter for node.js

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

filter2

A versatile stream filter for Node.js.

This package is not affliated with Tim-Smart’s filter.

Install

$ npm install filter2

Usage

var filter = require('filter2')

Passthrough (do nothing)

fs.createReadStream('./foo.txt')
  .pipe(filter())

Get the first 5 chunks

fs.createReadStream('./foo.txt')
  .pipe(filter.head(5))

Get the last 5 chunks

fs.createReadStream('./foo.txt')
  .pipe(filter.tail(5))

Get the filtered chunks

fs.createReadStream('./foo.txt')
  .pipe(filter(function(chunk, encoding, next) {
    // returns true to make chunks flow downstream
    return /bar/.test(chunk, encoding, next)
  }))

Filter function get the same arguments as through2.

Usually filter only makes sense when using after filter.split().

Get a custom set in chunks

function MySet(n) {
	this._array = Array(n)
}
MySet.prototype.push = function(thing) {
	// filter input as you wish 
	this._array.push(thing)
}
MySet.prototype.forEach = function() {
	Array.prototype.forEach.apply(this._array, arguments)
}


var mySet = new MySet(4)
fs.createReadStream('./foo.txt')
  .pipe(filter.some(mySet))
  // each chunk is pushed into mySet
  // and when upstream drains, it
  // returns a set of chunks that mySet.forEach returns

Break up a stream and reassemble it

This is just an alias of Matteo Collina's split2. Please refers to split2 README for more details.

fs.createReadStream('./foo.txt')
  .pipe(filter.split())
  // split and rearrange chunks by line break

License

Copyright (c) 2015 Jingwei "John" Liu

Licensed under the MIT license.

FAQs

Package last updated on 21 Dec 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.