UNPKG

552 BJavaScriptView Raw
1// decode-buffer.js
2
3exports.DecodeBuffer = DecodeBuffer;
4
5var DEFAULT_OPTIONS = {};
6
7function DecodeBuffer(options) {
8 if (!(this instanceof DecodeBuffer)) return new DecodeBuffer(options);
9 this.options = options || DEFAULT_OPTIONS;
10}
11
12DecodeBuffer.prototype.push = Array.prototype.push;
13DecodeBuffer.prototype.read = Array.prototype.shift;
14
15DecodeBuffer.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};