@sevenqi/nodechannel
Version:
nodejs channel
50 lines • 1.95 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseChannel = void 0;
var stream_1 = require("stream");
var filter_1 = require("./filter");
var BaseChannel = /** @class */ (function (_super) {
__extends(BaseChannel, _super);
function BaseChannel(duplex, filter) {
var _this = _super.call(this, { readableObjectMode: true }) || this;
_this.filter = filter;
_this.duplex = duplex;
_this.duplex.pipe(_this);
_this.duplex.on("close", function () {
_this.onClose();
});
return _this;
}
BaseChannel.prototype._write = function (chunk, encoding, callback) {
if (!this.filter)
this.filter = new filter_1.StringFilter();
var result = this.filter.decodePackage(chunk);
if (result)
this.push(result);
callback();
};
BaseChannel.prototype._read = function (size) {
this.resume();
};
BaseChannel.prototype.send = function (buffer) {
this.duplex.write(buffer);
};
return BaseChannel;
}(stream_1.Duplex));
exports.BaseChannel = BaseChannel;
//# sourceMappingURL=baseChannel.js.map