-
Notifications
You must be signed in to change notification settings - Fork 418
/
BaseTransformer.js
40 lines (34 loc) · 938 Bytes
/
BaseTransformer.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
"use strict";
const util = require("util");
const Base = require("../../structures/Base");
const TransformStream = require("stream").Transform;
class BaseTransformer extends TransformStream {
constructor(options = {}) {
if(options.allowHalfOpen === undefined) {
options.allowHalfOpen = true;
}
if(options.highWaterMark === undefined) {
options.highWaterMark = 0;
}
super(options);
this.manualCB = false;
}
setTransformCB(cb) {
if(this.manualCB) {
this.transformCB();
this._transformCB = cb;
} else {
cb();
}
}
transformCB() {
if(this._transformCB) {
this._transformCB();
this._transformCB = null;
}
}
[util.inspect.custom]() {
return Base.prototype[util.inspect.custom].call(this);
}
}
module.exports = BaseTransformer;