1 |
|
2 |
|
3 | exports.DecodeBuffer = DecodeBuffer;
|
4 |
|
5 | var DEFAULT_OPTIONS = {};
|
6 |
|
7 | function DecodeBuffer(options) {
|
8 | if (!(this instanceof DecodeBuffer)) return new DecodeBuffer(options);
|
9 | this.options = options || DEFAULT_OPTIONS;
|
10 | }
|
11 |
|
12 | DecodeBuffer.prototype.push = Array.prototype.push;
|
13 | DecodeBuffer.prototype.read = Array.prototype.shift;
|
14 |
|
15 | DecodeBuffer.prototype.append = function(chunk) {
|
16 | var prev = this.offset ? this.buffer.slice(this.offset) : this.buffer;
|
17 | this.buffer = prev ? Buffer.concat([prev, chunk]) : chunk;
|
18 | this.offset = 0;
|
19 | };
|