Files
hcapEnv/node_modules/msgpack-lite/lib/encoder.js
2026-02-21 18:27:49 +08:00

27 lines
580 B
JavaScript

// encoder.js
exports.Encoder = Encoder;
var EventLite = require("event-lite");
var EncodeBuffer = require("./encode-buffer").EncodeBuffer;
function Encoder(options) {
if (!(this instanceof Encoder)) return new Encoder(options);
EncodeBuffer.call(this, options);
}
Encoder.prototype = new EncodeBuffer();
EventLite.mixin(Encoder.prototype);
Encoder.prototype.encode = function(chunk) {
this.write(chunk);
this.emit("data", this.read());
};
Encoder.prototype.end = function(chunk) {
if (arguments.length) this.encode(chunk);
this.flush();
this.emit("end");
};