UNPKG

670 BJavaScriptView Raw
1// decoder.js
2
3exports.Decoder = Decoder;
4
5var EventLite = require("event-lite");
6var DecodeBuffer = require("./decode-buffer").DecodeBuffer;
7var decodeAsync = require("./read-core").decodeAsync;
8
9function Decoder(options) {
10 if (!(this instanceof Decoder)) return new Decoder(options);
11 DecodeBuffer.call(this, options);
12}
13
14Decoder.prototype = new DecodeBuffer();
15
16EventLite.mixin(Decoder.prototype);
17
18Decoder.prototype.decode = function(chunk) {
19 if (chunk) this.append(chunk);
20 decodeAsync(this);
21};
22
23Decoder.prototype.push = function(chunk) {
24 this.emit("data", chunk);
25};
26
27Decoder.prototype.end = function(chunk) {
28 this.decode(chunk);
29 this.emit("end");
30};