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