1 |
|
2 |
|
3 | exports.Encoder = Encoder;
|
4 |
|
5 | var EventLite = require("event-lite");
|
6 | var encode = require("./write-core").encode;
|
7 | var EncodeBuffer = require("./encode-buffer").EncodeBuffer;
|
8 |
|
9 | function Encoder(options) {
|
10 | if (!(this instanceof Encoder)) return new Encoder(options);
|
11 | EncodeBuffer.call(this, options);
|
12 | }
|
13 |
|
14 | Encoder.prototype = new EncodeBuffer();
|
15 |
|
16 | EventLite.mixin(Encoder.prototype);
|
17 |
|
18 | Encoder.prototype.encode = function(chunk) {
|
19 | encode(this, chunk);
|
20 | this.emit("data", this.read());
|
21 | };
|
22 |
|
23 | Encoder.prototype.end = function(chunk) {
|
24 | if (arguments.length) this.encode(chunk);
|
25 | this.flush();
|
26 | this.emit("end");
|
27 | };
|