3 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7 function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11 function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
13 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15 var _require = require('buffer'),
16 Buffer = _require.Buffer;
18 var _require2 = require('util'),
19 inspect = _require2.inspect;
21 var custom = inspect && inspect.custom || 'inspect';
23 function copyBuffer(src, target, offset) {
24 Buffer.prototype.copy.call(src, target, offset);
30 function BufferList() {
31 _classCallCheck(this, BufferList);
38 _createClass(BufferList, [{
40 value: function push(v) {
45 if (this.length > 0) this.tail.next = entry;else this.head = entry;
51 value: function unshift(v) {
56 if (this.length === 0) this.tail = entry;
62 value: function shift() {
63 if (this.length === 0) return;
64 var ret = this.head.data;
65 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
71 value: function clear() {
72 this.head = this.tail = null;
77 value: function join(s) {
78 if (this.length === 0) return '';
80 var ret = '' + p.data;
90 value: function concat(n) {
91 if (this.length === 0) return Buffer.alloc(0);
92 var ret = Buffer.allocUnsafe(n >>> 0);
97 copyBuffer(p.data, ret, i);
103 } // Consumes a specified amount of bytes or characters from the buffered data.
107 value: function consume(n, hasStrings) {
110 if (n < this.head.data.length) {
111 // `slice` is the same for buffers and strings.
112 ret = this.head.data.slice(0, n);
113 this.head.data = this.head.data.slice(n);
114 } else if (n === this.head.data.length) {
115 // First chunk is a perfect match.
118 // Result spans more than one buffer.
119 ret = hasStrings ? this._getString(n) : this._getBuffer(n);
126 value: function first() {
127 return this.head.data;
128 } // Consumes a specified amount of characters from the buffered data.
132 value: function _getString(n) {
140 var nb = n > str.length ? str.length : n;
141 if (nb === str.length) ret += str;else ret += str.slice(0, n);
145 if (nb === str.length) {
147 if (p.next) this.head = p.next;else this.head = this.tail = null;
150 p.data = str.slice(nb);
161 } // Consumes a specified amount of bytes from the buffered data.
165 value: function _getBuffer(n) {
166 var ret = Buffer.allocUnsafe(n);
174 var nb = n > buf.length ? buf.length : n;
175 buf.copy(ret, ret.length - n, 0, nb);
179 if (nb === buf.length) {
181 if (p.next) this.head = p.next;else this.head = this.tail = null;
184 p.data = buf.slice(nb);
195 } // Make sure the linked list only shows the minimal necessary information.
199 value: function value(_, options) {
200 return inspect(this, _objectSpread({}, options, {
201 // Only inspect one level.
203 // It should not recurse.