UNPKG

773 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 if(EVENTS[name] === 0){
19 cbs.prototype["on" + name] = function(){
20 this.scope.emit(name);
21 };
22 } else if(EVENTS[name] === 1){
23 cbs.prototype["on" + name] = function(a){
24 this.scope.emit(name, a);
25 };
26 } else if(EVENTS[name] === 2){
27 cbs.prototype["on" + name] = function(a, b){
28 this.scope.emit(name, a, b);
29 };
30 } else {
31 throw Error("wrong number of arguments!");
32 }
33});
34
35module.exports = Stream;
\No newline at end of file