Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
module.exports = Stream;
2
3
var Parser = require("./WritableStream.js");
4
5
function Stream(options){
6
Parser.call(this, new Cbs(this), options);
7
}
8
9
require("util").inherits(Stream, Parser);
10
11
Stream.prototype.readable = true;
12
13
function Cbs(scope){
14
this.scope = scope;
15
}
16
17
var EVENTS = require("../").EVENTS;
18
19
Object.keys(EVENTS).forEach(function(name){
20
if(EVENTS[name] === 0){
21
Cbs.prototype["on" + name] = function(){
22
this.scope.emit(name);
23
};
24
} else if(EVENTS[name] === 1){
25
Cbs.prototype["on" + name] = function(a){
26
this.scope.emit(name, a);
27
};
28
} else if(EVENTS[name] === 2){
29
Cbs.prototype["on" + name] = function(a, b){
30
this.scope.emit(name, a, b);
31
};
32
} else {
33
throw Error("wrong number of arguments!");
34
}
35
});
36