-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4Filter.js
50 lines (40 loc) · 1.03 KB
/
p4Filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var stream = require('stream');
var util = require('util');
var os = require('os');
var debug = require('debug')('p4Filter');
var Transform = stream.Transform;
util.inherits(P4Filter, Transform);
function P4Filter(options)
{
if (!(this instanceof P4Filter))
return new P4Filter(options);
if(options && options.excludeFilters)
{
this._excludeFilters = options.excludeFilters;
debug('exclude filters: ' + this._excludeFilters);
}
Transform.call(this, { objectMode: true });
}
P4Filter.prototype._transform = function (chunk, encoding, done) {
var buff = chunk.toString();
if (buff && buff.length > 0)
{
buff = buff.toLowerCase();
buff = buff + os.EOL;
if (this._excludeFilters)
{
var bInclude = true;
this._excludeFilters.forEach(function(element, index){
if (buff.indexOf(element) !== -1)
bInclude = false;
});
if (bInclude)
this.push(buff);
}
}
done();
}
P4Filter.prototype._flush = function (done) {
done()
}
module.exports = P4Filter