Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buffer_list.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. 'use strict';
  2. 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; }
  3. 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; }
  4. 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; }
  5. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6. 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); } }
  7. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8. var _require = require('buffer'),
  9. Buffer = _require.Buffer;
  10. var _require2 = require('util'),
  11. inspect = _require2.inspect;
  12. var custom = inspect && inspect.custom || 'inspect';
  13. function copyBuffer(src, target, offset) {
  14. Buffer.prototype.copy.call(src, target, offset);
  15. }
  16. module.exports =
  17. /*#__PURE__*/
  18. function () {
  19. function BufferList() {
  20. _classCallCheck(this, BufferList);
  21. this.head = null;
  22. this.tail = null;
  23. this.length = 0;
  24. }
  25. _createClass(BufferList, [{
  26. key: "push",
  27. value: function push(v) {
  28. var entry = {
  29. data: v,
  30. next: null
  31. };
  32. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  33. this.tail = entry;
  34. ++this.length;
  35. }
  36. }, {
  37. key: "unshift",
  38. value: function unshift(v) {
  39. var entry = {
  40. data: v,
  41. next: this.head
  42. };
  43. if (this.length === 0) this.tail = entry;
  44. this.head = entry;
  45. ++this.length;
  46. }
  47. }, {
  48. key: "shift",
  49. value: function shift() {
  50. if (this.length === 0) return;
  51. var ret = this.head.data;
  52. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  53. --this.length;
  54. return ret;
  55. }
  56. }, {
  57. key: "clear",
  58. value: function clear() {
  59. this.head = this.tail = null;
  60. this.length = 0;
  61. }
  62. }, {
  63. key: "join",
  64. value: function join(s) {
  65. if (this.length === 0) return '';
  66. var p = this.head;
  67. var ret = '' + p.data;
  68. while (p = p.next) {
  69. ret += s + p.data;
  70. }
  71. return ret;
  72. }
  73. }, {
  74. key: "concat",
  75. value: function concat(n) {
  76. if (this.length === 0) return Buffer.alloc(0);
  77. var ret = Buffer.allocUnsafe(n >>> 0);
  78. var p = this.head;
  79. var i = 0;
  80. while (p) {
  81. copyBuffer(p.data, ret, i);
  82. i += p.data.length;
  83. p = p.next;
  84. }
  85. return ret;
  86. } // Consumes a specified amount of bytes or characters from the buffered data.
  87. }, {
  88. key: "consume",
  89. value: function consume(n, hasStrings) {
  90. var ret;
  91. if (n < this.head.data.length) {
  92. // `slice` is the same for buffers and strings.
  93. ret = this.head.data.slice(0, n);
  94. this.head.data = this.head.data.slice(n);
  95. } else if (n === this.head.data.length) {
  96. // First chunk is a perfect match.
  97. ret = this.shift();
  98. } else {
  99. // Result spans more than one buffer.
  100. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  101. }
  102. return ret;
  103. }
  104. }, {
  105. key: "first",
  106. value: function first() {
  107. return this.head.data;
  108. } // Consumes a specified amount of characters from the buffered data.
  109. }, {
  110. key: "_getString",
  111. value: function _getString(n) {
  112. var p = this.head;
  113. var c = 1;
  114. var ret = p.data;
  115. n -= ret.length;
  116. while (p = p.next) {
  117. var str = p.data;
  118. var nb = n > str.length ? str.length : n;
  119. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  120. n -= nb;
  121. if (n === 0) {
  122. if (nb === str.length) {
  123. ++c;
  124. if (p.next) this.head = p.next;else this.head = this.tail = null;
  125. } else {
  126. this.head = p;
  127. p.data = str.slice(nb);
  128. }
  129. break;
  130. }
  131. ++c;
  132. }
  133. this.length -= c;
  134. return ret;
  135. } // Consumes a specified amount of bytes from the buffered data.
  136. }, {
  137. key: "_getBuffer",
  138. value: function _getBuffer(n) {
  139. var ret = Buffer.allocUnsafe(n);
  140. var p = this.head;
  141. var c = 1;
  142. p.data.copy(ret);
  143. n -= p.data.length;
  144. while (p = p.next) {
  145. var buf = p.data;
  146. var nb = n > buf.length ? buf.length : n;
  147. buf.copy(ret, ret.length - n, 0, nb);
  148. n -= nb;
  149. if (n === 0) {
  150. if (nb === buf.length) {
  151. ++c;
  152. if (p.next) this.head = p.next;else this.head = this.tail = null;
  153. } else {
  154. this.head = p;
  155. p.data = buf.slice(nb);
  156. }
  157. break;
  158. }
  159. ++c;
  160. }
  161. this.length -= c;
  162. return ret;
  163. } // Make sure the linked list only shows the minimal necessary information.
  164. }, {
  165. key: custom,
  166. value: function value(_, options) {
  167. return inspect(this, _objectSpread({}, options, {
  168. // Only inspect one level.
  169. depth: 0,
  170. // It should not recurse.
  171. customInspect: false
  172. }));
  173. }
  174. }]);
  175. return BufferList;
  176. }();