3 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5 var Buffer = require('safe-buffer').Buffer;
6 var util = require('util');
8 function copyBuffer(src, target, offset) {
9 src.copy(target, offset);
12 module.exports = function () {
13 function BufferList() {
14 _classCallCheck(this, BufferList);
21 BufferList.prototype.push = function push(v) {
22 var entry = { data: v, next: null };
23 if (this.length > 0) this.tail.next = entry;else this.head = entry;
28 BufferList.prototype.unshift = function unshift(v) {
29 var entry = { data: v, next: this.head };
30 if (this.length === 0) this.tail = entry;
35 BufferList.prototype.shift = function shift() {
36 if (this.length === 0) return;
37 var ret = this.head.data;
38 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
43 BufferList.prototype.clear = function clear() {
44 this.head = this.tail = null;
48 BufferList.prototype.join = function join(s) {
49 if (this.length === 0) return '';
51 var ret = '' + p.data;
57 BufferList.prototype.concat = function concat(n) {
58 if (this.length === 0) return Buffer.alloc(0);
59 if (this.length === 1) return this.head.data;
60 var ret = Buffer.allocUnsafe(n >>> 0);
64 copyBuffer(p.data, ret, i);
74 if (util && util.inspect && util.inspect.custom) {
75 module.exports.prototype[util.inspect.custom] = function () {
76 var obj = util.inspect({ length: this.length });
77 return this.constructor.name + ' ' + obj;