UNPKG

790 BJavaScriptView Raw
1var WritableStream = require("./WritableStream.js");
2
3var Stream = function(options){
4 WritableStream.call(this, new cbs(this), options);
5};
6
7require("util").inherits(Stream, WritableStream);
8
9Stream.prototype.readable = true;
10
11var cbs = function(scope){
12 this.scope = scope;
13};
14
15var EVENTS = require("../").EVENTS;
16
17Object.keys(EVENTS).forEach(function(name){
18 switch(EVENTS[name]){
19 case 0:{
20 cbs.prototype["on" + name] = function(){
21 this.scope.emit(name);
22 };
23 break;
24 }
25 case 1:{
26 cbs.prototype["on" + name] = function(a){
27 this.scope.emit(name, a);
28 };
29 break;
30 }
31 case 2:{
32 cbs.prototype["on" + name] = function(a, b){
33 this.scope.emit(name, a, b);
34 };
35 break;
36 }
37 default: throw Error("wrong number of arguments!");
38 }
39});
40
41module.exports = Stream;
\No newline at end of file