You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Stream.js 833B

1234567891011121314151617181920212223242526272829303132333435
  1. module.exports = Stream;
  2. var Parser = require("./WritableStream.js");
  3. function Stream(options) {
  4. Parser.call(this, new Cbs(this), options);
  5. }
  6. require("inherits")(Stream, Parser);
  7. Stream.prototype.readable = true;
  8. function Cbs(scope) {
  9. this.scope = scope;
  10. }
  11. var EVENTS = require("../").EVENTS;
  12. Object.keys(EVENTS).forEach(function(name) {
  13. if (EVENTS[name] === 0) {
  14. Cbs.prototype["on" + name] = function() {
  15. this.scope.emit(name);
  16. };
  17. } else if (EVENTS[name] === 1) {
  18. Cbs.prototype["on" + name] = function(a) {
  19. this.scope.emit(name, a);
  20. };
  21. } else if (EVENTS[name] === 2) {
  22. Cbs.prototype["on" + name] = function(a, b) {
  23. this.scope.emit(name, a, b);
  24. };
  25. } else {
  26. throw Error("wrong number of arguments!");
  27. }
  28. });