@verdocs/web-sdk 1.4.7 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/cjs/VerdocsEndpoint-5e6dd8ef.js +4780 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/verdocs-auth.cjs.entry.js +32 -19
  4. package/dist/cjs/verdocs-dropdown_12.cjs.entry.js +15 -11
  5. package/dist/cjs/verdocs-kba-dialog.cjs.entry.js +1 -1
  6. package/dist/cjs/verdocs-ok-dialog.cjs.entry.js +1 -1
  7. package/dist/cjs/verdocs-quick-functions.cjs.entry.js +5 -0
  8. package/dist/cjs/verdocs-search-activity_2.cjs.entry.js +40 -35
  9. package/dist/cjs/verdocs-search.cjs.entry.js +6 -1
  10. package/dist/cjs/verdocs-sign.cjs.entry.js +26 -161
  11. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  12. package/dist/collection/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.css +1 -1
  13. package/dist/collection/components/dialogs/verdocs-ok-dialog/verdocs-ok-dialog.css +1 -1
  14. package/dist/collection/components/elements/verdocs-quick-functions/verdocs-quick-functions.js +31 -1
  15. package/dist/collection/components/elements/verdocs-search-activity/verdocs-search-activity.js +30 -6
  16. package/dist/collection/components/elements/verdocs-search-box/verdocs-search-box.js +26 -0
  17. package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.css +1 -4
  18. package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.js +35 -17
  19. package/dist/collection/components/embeds/verdocs-search/verdocs-search.js +36 -6
  20. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.css +27 -26
  21. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.js +40 -23
  22. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.stories.js +2 -2
  23. package/dist/collection/components/embeds/verdocs-view/verdocs-view.js +26 -0
  24. package/dist/components/VerdocsEndpoint.js +4766 -0
  25. package/dist/components/verdocs-auth.js +33 -18
  26. package/dist/components/verdocs-kba-dialog.js +1 -1
  27. package/dist/components/verdocs-ok-dialog2.js +1 -1
  28. package/dist/components/verdocs-quick-functions.js +8 -1
  29. package/dist/components/verdocs-search-activity2.js +37 -34
  30. package/dist/components/verdocs-search-box2.js +6 -0
  31. package/dist/components/verdocs-search.js +9 -2
  32. package/dist/components/verdocs-sign.js +27 -162
  33. package/dist/components/verdocs-view2.js +6 -1
  34. package/dist/custom-elements.json +830 -0
  35. package/dist/docs.json +117 -3
  36. package/dist/esm/VerdocsEndpoint-30e1b6ec.js +4766 -0
  37. package/dist/esm/loader.js +1 -1
  38. package/dist/esm/verdocs-auth.entry.js +32 -19
  39. package/dist/esm/verdocs-dropdown_12.entry.js +5 -1
  40. package/dist/esm/verdocs-kba-dialog.entry.js +1 -1
  41. package/dist/esm/verdocs-ok-dialog.entry.js +1 -1
  42. package/dist/esm/verdocs-quick-functions.entry.js +5 -0
  43. package/dist/esm/verdocs-search-activity_2.entry.js +40 -35
  44. package/dist/esm/verdocs-search.entry.js +6 -1
  45. package/dist/esm/verdocs-sign.entry.js +26 -161
  46. package/dist/esm/verdocs-web-sdk.js +1 -1
  47. package/dist/esm-es5/VerdocsEndpoint-30e1b6ec.js +7 -0
  48. package/dist/esm-es5/loader.js +1 -1
  49. package/dist/esm-es5/verdocs-auth.entry.js +1 -1
  50. package/dist/esm-es5/verdocs-dropdown_12.entry.js +2 -2
  51. package/dist/esm-es5/verdocs-kba-dialog.entry.js +1 -1
  52. package/dist/esm-es5/verdocs-ok-dialog.entry.js +1 -1
  53. package/dist/esm-es5/verdocs-quick-functions.entry.js +1 -1
  54. package/dist/esm-es5/verdocs-search-activity_2.entry.js +1 -1
  55. package/dist/esm-es5/verdocs-search.entry.js +1 -1
  56. package/dist/esm-es5/verdocs-sign.entry.js +1 -1
  57. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  58. package/dist/types/components/elements/verdocs-quick-functions/verdocs-quick-functions.d.ts +5 -0
  59. package/dist/types/components/elements/verdocs-search-activity/verdocs-search-activity.d.ts +5 -0
  60. package/dist/types/components/elements/verdocs-search-box/verdocs-search-box.d.ts +5 -0
  61. package/dist/types/components/embeds/verdocs-auth/verdocs-auth.d.ts +7 -4
  62. package/dist/types/components/embeds/verdocs-search/verdocs-search.d.ts +5 -0
  63. package/dist/types/components/embeds/verdocs-sign/verdocs-sign.d.ts +6 -3
  64. package/dist/types/components/embeds/verdocs-view/verdocs-view.d.ts +5 -0
  65. package/dist/types/components.d.ts +57 -0
  66. package/dist/verdocs-web-sdk/{p-ed5baeb4.entry.js → p-064453c3.entry.js} +1 -1
  67. package/dist/verdocs-web-sdk/p-06f38046.js +1 -0
  68. package/dist/verdocs-web-sdk/p-16d62a51.system.entry.js +1 -0
  69. package/dist/verdocs-web-sdk/p-1b4e04b7.system.entry.js +1 -0
  70. package/dist/verdocs-web-sdk/p-1ea3b9d3.entry.js +1 -0
  71. package/dist/verdocs-web-sdk/p-30cc8818.entry.js +1 -0
  72. package/dist/verdocs-web-sdk/{p-0353c423.entry.js → p-32ad1014.entry.js} +1 -1
  73. package/dist/verdocs-web-sdk/p-4d80d044.system.js +7 -0
  74. package/dist/verdocs-web-sdk/{p-432c3151.system.entry.js → p-81fc0196.system.entry.js} +1 -1
  75. package/dist/verdocs-web-sdk/p-8276345a.entry.js +1 -0
  76. package/dist/verdocs-web-sdk/p-88a300c5.system.js +1 -1
  77. package/dist/verdocs-web-sdk/p-9139a76d.system.entry.js +1 -0
  78. package/dist/verdocs-web-sdk/p-a87069d5.system.entry.js +1 -0
  79. package/dist/verdocs-web-sdk/p-aa9fc574.entry.js +1 -0
  80. package/dist/verdocs-web-sdk/p-c29c2cf8.entry.js +1 -0
  81. package/dist/verdocs-web-sdk/{p-4368df79.system.entry.js → p-c4d03ff9.system.entry.js} +2 -2
  82. package/dist/verdocs-web-sdk/{p-a1143ddb.entry.js → p-d522de7d.entry.js} +2 -2
  83. package/dist/verdocs-web-sdk/{p-e2e643c5.system.entry.js → p-e4ba14dc.system.entry.js} +1 -1
  84. package/dist/verdocs-web-sdk/p-f6a53928.system.entry.js +1 -0
  85. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  86. package/package.json +2 -2
  87. package/dist/cjs/Auth-4ec35ac7.js +0 -97
  88. package/dist/cjs/Token-ac80819a.js +0 -2331
  89. package/dist/cjs/buffer-es6-bc8199b1.js +0 -2018
  90. package/dist/components/Auth.js +0 -92
  91. package/dist/components/Token.js +0 -2325
  92. package/dist/components/buffer-es6.js +0 -2010
  93. package/dist/esm/Auth-15cd42a8.js +0 -92
  94. package/dist/esm/Token-ce37bd9d.js +0 -2325
  95. package/dist/esm/buffer-es6-136673c8.js +0 -2010
  96. package/dist/esm-es5/Auth-15cd42a8.js +0 -1
  97. package/dist/esm-es5/Token-ce37bd9d.js +0 -1
  98. package/dist/esm-es5/buffer-es6-136673c8.js +0 -7
  99. package/dist/verdocs-web-sdk/p-0c0b4a10.system.entry.js +0 -1
  100. package/dist/verdocs-web-sdk/p-2b57857d.system.entry.js +0 -1
  101. package/dist/verdocs-web-sdk/p-2c161242.system.entry.js +0 -1
  102. package/dist/verdocs-web-sdk/p-39633a02.entry.js +0 -1
  103. package/dist/verdocs-web-sdk/p-5dfd73f9.system.js +0 -7
  104. package/dist/verdocs-web-sdk/p-69ef22bd.entry.js +0 -1
  105. package/dist/verdocs-web-sdk/p-737b2e99.js +0 -1
  106. package/dist/verdocs-web-sdk/p-8730dc92.system.js +0 -1
  107. package/dist/verdocs-web-sdk/p-a7cfe6fc.entry.js +0 -1
  108. package/dist/verdocs-web-sdk/p-b9164c4b.system.entry.js +0 -1
  109. package/dist/verdocs-web-sdk/p-cec13589.system.js +0 -1
  110. package/dist/verdocs-web-sdk/p-e6e2894e.js +0 -1
  111. package/dist/verdocs-web-sdk/p-ea6d6dc7.entry.js +0 -1
  112. package/dist/verdocs-web-sdk/p-ef932a87.js +0 -1
  113. package/dist/verdocs-web-sdk/p-f0e6fde0.entry.js +0 -1
  114. package/dist/verdocs-web-sdk/p-fd853e54.system.entry.js +0 -1
@@ -1,2010 +0,0 @@
1
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
-
3
- function getDefaultExportFromCjs (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
- function createCommonjsModule(fn, basedir, module) {
8
- return module = {
9
- path: basedir,
10
- exports: {},
11
- require: function (path, base) {
12
- return commonjsRequire();
13
- }
14
- }, fn(module, module.exports), module.exports;
15
- }
16
-
17
- function getAugmentedNamespace(n) {
18
- if (n.__esModule) return n;
19
- var a = Object.defineProperty({}, '__esModule', {value: true});
20
- Object.keys(n).forEach(function (k) {
21
- var d = Object.getOwnPropertyDescriptor(n, k);
22
- Object.defineProperty(a, k, d.get ? d : {
23
- enumerable: true,
24
- get: function () {
25
- return n[k];
26
- }
27
- });
28
- });
29
- return a;
30
- }
31
-
32
- function commonjsRequire () {
33
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
34
- }
35
-
36
- // for now just expose the builtin process global from node.js
37
- var process_1 = commonjsGlobal.process;
38
-
39
- const global$1 = (typeof global !== "undefined" ? global :
40
- typeof self !== "undefined" ? self :
41
- typeof window !== "undefined" ? window : {});
42
-
43
- var lookup = [];
44
- var revLookup = [];
45
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
46
- var inited = false;
47
- function init () {
48
- inited = true;
49
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
50
- for (var i = 0, len = code.length; i < len; ++i) {
51
- lookup[i] = code[i];
52
- revLookup[code.charCodeAt(i)] = i;
53
- }
54
-
55
- revLookup['-'.charCodeAt(0)] = 62;
56
- revLookup['_'.charCodeAt(0)] = 63;
57
- }
58
-
59
- function toByteArray (b64) {
60
- if (!inited) {
61
- init();
62
- }
63
- var i, j, l, tmp, placeHolders, arr;
64
- var len = b64.length;
65
-
66
- if (len % 4 > 0) {
67
- throw new Error('Invalid string. Length must be a multiple of 4')
68
- }
69
-
70
- // the number of equal signs (place holders)
71
- // if there are two placeholders, than the two characters before it
72
- // represent one byte
73
- // if there is only one, then the three characters before it represent 2 bytes
74
- // this is just a cheap hack to not do indexOf twice
75
- placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
76
-
77
- // base64 is 4/3 + up to two characters of the original data
78
- arr = new Arr(len * 3 / 4 - placeHolders);
79
-
80
- // if there are placeholders, only get up to the last complete 4 chars
81
- l = placeHolders > 0 ? len - 4 : len;
82
-
83
- var L = 0;
84
-
85
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
86
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
87
- arr[L++] = (tmp >> 16) & 0xFF;
88
- arr[L++] = (tmp >> 8) & 0xFF;
89
- arr[L++] = tmp & 0xFF;
90
- }
91
-
92
- if (placeHolders === 2) {
93
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
94
- arr[L++] = tmp & 0xFF;
95
- } else if (placeHolders === 1) {
96
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
97
- arr[L++] = (tmp >> 8) & 0xFF;
98
- arr[L++] = tmp & 0xFF;
99
- }
100
-
101
- return arr
102
- }
103
-
104
- function tripletToBase64 (num) {
105
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
106
- }
107
-
108
- function encodeChunk (uint8, start, end) {
109
- var tmp;
110
- var output = [];
111
- for (var i = start; i < end; i += 3) {
112
- tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
113
- output.push(tripletToBase64(tmp));
114
- }
115
- return output.join('')
116
- }
117
-
118
- function fromByteArray (uint8) {
119
- if (!inited) {
120
- init();
121
- }
122
- var tmp;
123
- var len = uint8.length;
124
- var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
125
- var output = '';
126
- var parts = [];
127
- var maxChunkLength = 16383; // must be multiple of 3
128
-
129
- // go through the array every three bytes, we'll deal with trailing stuff later
130
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
131
- parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
132
- }
133
-
134
- // pad the end with zeros, but make sure to not forget the extra bytes
135
- if (extraBytes === 1) {
136
- tmp = uint8[len - 1];
137
- output += lookup[tmp >> 2];
138
- output += lookup[(tmp << 4) & 0x3F];
139
- output += '==';
140
- } else if (extraBytes === 2) {
141
- tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
142
- output += lookup[tmp >> 10];
143
- output += lookup[(tmp >> 4) & 0x3F];
144
- output += lookup[(tmp << 2) & 0x3F];
145
- output += '=';
146
- }
147
-
148
- parts.push(output);
149
-
150
- return parts.join('')
151
- }
152
-
153
- function read (buffer, offset, isLE, mLen, nBytes) {
154
- var e, m;
155
- var eLen = nBytes * 8 - mLen - 1;
156
- var eMax = (1 << eLen) - 1;
157
- var eBias = eMax >> 1;
158
- var nBits = -7;
159
- var i = isLE ? (nBytes - 1) : 0;
160
- var d = isLE ? -1 : 1;
161
- var s = buffer[offset + i];
162
-
163
- i += d;
164
-
165
- e = s & ((1 << (-nBits)) - 1);
166
- s >>= (-nBits);
167
- nBits += eLen;
168
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
169
-
170
- m = e & ((1 << (-nBits)) - 1);
171
- e >>= (-nBits);
172
- nBits += mLen;
173
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
174
-
175
- if (e === 0) {
176
- e = 1 - eBias;
177
- } else if (e === eMax) {
178
- return m ? NaN : ((s ? -1 : 1) * Infinity)
179
- } else {
180
- m = m + Math.pow(2, mLen);
181
- e = e - eBias;
182
- }
183
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
184
- }
185
-
186
- function write (buffer, value, offset, isLE, mLen, nBytes) {
187
- var e, m, c;
188
- var eLen = nBytes * 8 - mLen - 1;
189
- var eMax = (1 << eLen) - 1;
190
- var eBias = eMax >> 1;
191
- var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
192
- var i = isLE ? 0 : (nBytes - 1);
193
- var d = isLE ? 1 : -1;
194
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
195
-
196
- value = Math.abs(value);
197
-
198
- if (isNaN(value) || value === Infinity) {
199
- m = isNaN(value) ? 1 : 0;
200
- e = eMax;
201
- } else {
202
- e = Math.floor(Math.log(value) / Math.LN2);
203
- if (value * (c = Math.pow(2, -e)) < 1) {
204
- e--;
205
- c *= 2;
206
- }
207
- if (e + eBias >= 1) {
208
- value += rt / c;
209
- } else {
210
- value += rt * Math.pow(2, 1 - eBias);
211
- }
212
- if (value * c >= 2) {
213
- e++;
214
- c /= 2;
215
- }
216
-
217
- if (e + eBias >= eMax) {
218
- m = 0;
219
- e = eMax;
220
- } else if (e + eBias >= 1) {
221
- m = (value * c - 1) * Math.pow(2, mLen);
222
- e = e + eBias;
223
- } else {
224
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
225
- e = 0;
226
- }
227
- }
228
-
229
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
230
-
231
- e = (e << mLen) | m;
232
- eLen += mLen;
233
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
234
-
235
- buffer[offset + i - d] |= s * 128;
236
- }
237
-
238
- var toString = {}.toString;
239
-
240
- var isArray = Array.isArray || function (arr) {
241
- return toString.call(arr) == '[object Array]';
242
- };
243
-
244
- /*!
245
- * The buffer module from node.js, for the browser.
246
- *
247
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
248
- * @license MIT
249
- */
250
-
251
- var INSPECT_MAX_BYTES = 50;
252
-
253
- /**
254
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
255
- * === true Use Uint8Array implementation (fastest)
256
- * === false Use Object implementation (most compatible, even IE6)
257
- *
258
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
259
- * Opera 11.6+, iOS 4.2+.
260
- *
261
- * Due to various browser bugs, sometimes the Object implementation will be used even
262
- * when the browser supports typed arrays.
263
- *
264
- * Note:
265
- *
266
- * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
267
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
268
- *
269
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
270
- *
271
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
272
- * incorrect length in some situations.
273
-
274
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
275
- * get the Object implementation, which is slower but behaves correctly.
276
- */
277
- Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
278
- ? global$1.TYPED_ARRAY_SUPPORT
279
- : true;
280
-
281
- function kMaxLength () {
282
- return Buffer.TYPED_ARRAY_SUPPORT
283
- ? 0x7fffffff
284
- : 0x3fffffff
285
- }
286
-
287
- function createBuffer (that, length) {
288
- if (kMaxLength() < length) {
289
- throw new RangeError('Invalid typed array length')
290
- }
291
- if (Buffer.TYPED_ARRAY_SUPPORT) {
292
- // Return an augmented `Uint8Array` instance, for best performance
293
- that = new Uint8Array(length);
294
- that.__proto__ = Buffer.prototype;
295
- } else {
296
- // Fallback: Return an object instance of the Buffer class
297
- if (that === null) {
298
- that = new Buffer(length);
299
- }
300
- that.length = length;
301
- }
302
-
303
- return that
304
- }
305
-
306
- /**
307
- * The Buffer constructor returns instances of `Uint8Array` that have their
308
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
309
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
310
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
311
- * returns a single octet.
312
- *
313
- * The `Uint8Array` prototype remains unmodified.
314
- */
315
-
316
- function Buffer (arg, encodingOrOffset, length) {
317
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
318
- return new Buffer(arg, encodingOrOffset, length)
319
- }
320
-
321
- // Common case.
322
- if (typeof arg === 'number') {
323
- if (typeof encodingOrOffset === 'string') {
324
- throw new Error(
325
- 'If encoding is specified then the first argument must be a string'
326
- )
327
- }
328
- return allocUnsafe(this, arg)
329
- }
330
- return from(this, arg, encodingOrOffset, length)
331
- }
332
-
333
- Buffer.poolSize = 8192; // not used by this implementation
334
-
335
- // TODO: Legacy, not needed anymore. Remove in next major version.
336
- Buffer._augment = function (arr) {
337
- arr.__proto__ = Buffer.prototype;
338
- return arr
339
- };
340
-
341
- function from (that, value, encodingOrOffset, length) {
342
- if (typeof value === 'number') {
343
- throw new TypeError('"value" argument must not be a number')
344
- }
345
-
346
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
347
- return fromArrayBuffer(that, value, encodingOrOffset, length)
348
- }
349
-
350
- if (typeof value === 'string') {
351
- return fromString(that, value, encodingOrOffset)
352
- }
353
-
354
- return fromObject(that, value)
355
- }
356
-
357
- /**
358
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
359
- * if value is a number.
360
- * Buffer.from(str[, encoding])
361
- * Buffer.from(array)
362
- * Buffer.from(buffer)
363
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
364
- **/
365
- Buffer.from = function (value, encodingOrOffset, length) {
366
- return from(null, value, encodingOrOffset, length)
367
- };
368
-
369
- if (Buffer.TYPED_ARRAY_SUPPORT) {
370
- Buffer.prototype.__proto__ = Uint8Array.prototype;
371
- Buffer.__proto__ = Uint8Array;
372
- }
373
-
374
- function assertSize (size) {
375
- if (typeof size !== 'number') {
376
- throw new TypeError('"size" argument must be a number')
377
- } else if (size < 0) {
378
- throw new RangeError('"size" argument must not be negative')
379
- }
380
- }
381
-
382
- function alloc (that, size, fill, encoding) {
383
- assertSize(size);
384
- if (size <= 0) {
385
- return createBuffer(that, size)
386
- }
387
- if (fill !== undefined) {
388
- // Only pay attention to encoding if it's a string. This
389
- // prevents accidentally sending in a number that would
390
- // be interpretted as a start offset.
391
- return typeof encoding === 'string'
392
- ? createBuffer(that, size).fill(fill, encoding)
393
- : createBuffer(that, size).fill(fill)
394
- }
395
- return createBuffer(that, size)
396
- }
397
-
398
- /**
399
- * Creates a new filled Buffer instance.
400
- * alloc(size[, fill[, encoding]])
401
- **/
402
- Buffer.alloc = function (size, fill, encoding) {
403
- return alloc(null, size, fill, encoding)
404
- };
405
-
406
- function allocUnsafe (that, size) {
407
- assertSize(size);
408
- that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
409
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
410
- for (var i = 0; i < size; ++i) {
411
- that[i] = 0;
412
- }
413
- }
414
- return that
415
- }
416
-
417
- /**
418
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
419
- * */
420
- Buffer.allocUnsafe = function (size) {
421
- return allocUnsafe(null, size)
422
- };
423
- /**
424
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
425
- */
426
- Buffer.allocUnsafeSlow = function (size) {
427
- return allocUnsafe(null, size)
428
- };
429
-
430
- function fromString (that, string, encoding) {
431
- if (typeof encoding !== 'string' || encoding === '') {
432
- encoding = 'utf8';
433
- }
434
-
435
- if (!Buffer.isEncoding(encoding)) {
436
- throw new TypeError('"encoding" must be a valid string encoding')
437
- }
438
-
439
- var length = byteLength(string, encoding) | 0;
440
- that = createBuffer(that, length);
441
-
442
- var actual = that.write(string, encoding);
443
-
444
- if (actual !== length) {
445
- // Writing a hex string, for example, that contains invalid characters will
446
- // cause everything after the first invalid character to be ignored. (e.g.
447
- // 'abxxcd' will be treated as 'ab')
448
- that = that.slice(0, actual);
449
- }
450
-
451
- return that
452
- }
453
-
454
- function fromArrayLike (that, array) {
455
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
456
- that = createBuffer(that, length);
457
- for (var i = 0; i < length; i += 1) {
458
- that[i] = array[i] & 255;
459
- }
460
- return that
461
- }
462
-
463
- function fromArrayBuffer (that, array, byteOffset, length) {
464
-
465
- if (byteOffset < 0 || array.byteLength < byteOffset) {
466
- throw new RangeError('\'offset\' is out of bounds')
467
- }
468
-
469
- if (array.byteLength < byteOffset + (length || 0)) {
470
- throw new RangeError('\'length\' is out of bounds')
471
- }
472
-
473
- if (byteOffset === undefined && length === undefined) {
474
- array = new Uint8Array(array);
475
- } else if (length === undefined) {
476
- array = new Uint8Array(array, byteOffset);
477
- } else {
478
- array = new Uint8Array(array, byteOffset, length);
479
- }
480
-
481
- if (Buffer.TYPED_ARRAY_SUPPORT) {
482
- // Return an augmented `Uint8Array` instance, for best performance
483
- that = array;
484
- that.__proto__ = Buffer.prototype;
485
- } else {
486
- // Fallback: Return an object instance of the Buffer class
487
- that = fromArrayLike(that, array);
488
- }
489
- return that
490
- }
491
-
492
- function fromObject (that, obj) {
493
- if (internalIsBuffer(obj)) {
494
- var len = checked(obj.length) | 0;
495
- that = createBuffer(that, len);
496
-
497
- if (that.length === 0) {
498
- return that
499
- }
500
-
501
- obj.copy(that, 0, 0, len);
502
- return that
503
- }
504
-
505
- if (obj) {
506
- if ((typeof ArrayBuffer !== 'undefined' &&
507
- obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
508
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
509
- return createBuffer(that, 0)
510
- }
511
- return fromArrayLike(that, obj)
512
- }
513
-
514
- if (obj.type === 'Buffer' && isArray(obj.data)) {
515
- return fromArrayLike(that, obj.data)
516
- }
517
- }
518
-
519
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
520
- }
521
-
522
- function checked (length) {
523
- // Note: cannot use `length < kMaxLength()` here because that fails when
524
- // length is NaN (which is otherwise coerced to zero.)
525
- if (length >= kMaxLength()) {
526
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
527
- 'size: 0x' + kMaxLength().toString(16) + ' bytes')
528
- }
529
- return length | 0
530
- }
531
- Buffer.isBuffer = isBuffer;
532
- function internalIsBuffer (b) {
533
- return !!(b != null && b._isBuffer)
534
- }
535
-
536
- Buffer.compare = function compare (a, b) {
537
- if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
538
- throw new TypeError('Arguments must be Buffers')
539
- }
540
-
541
- if (a === b) return 0
542
-
543
- var x = a.length;
544
- var y = b.length;
545
-
546
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
547
- if (a[i] !== b[i]) {
548
- x = a[i];
549
- y = b[i];
550
- break
551
- }
552
- }
553
-
554
- if (x < y) return -1
555
- if (y < x) return 1
556
- return 0
557
- };
558
-
559
- Buffer.isEncoding = function isEncoding (encoding) {
560
- switch (String(encoding).toLowerCase()) {
561
- case 'hex':
562
- case 'utf8':
563
- case 'utf-8':
564
- case 'ascii':
565
- case 'latin1':
566
- case 'binary':
567
- case 'base64':
568
- case 'ucs2':
569
- case 'ucs-2':
570
- case 'utf16le':
571
- case 'utf-16le':
572
- return true
573
- default:
574
- return false
575
- }
576
- };
577
-
578
- Buffer.concat = function concat (list, length) {
579
- if (!isArray(list)) {
580
- throw new TypeError('"list" argument must be an Array of Buffers')
581
- }
582
-
583
- if (list.length === 0) {
584
- return Buffer.alloc(0)
585
- }
586
-
587
- var i;
588
- if (length === undefined) {
589
- length = 0;
590
- for (i = 0; i < list.length; ++i) {
591
- length += list[i].length;
592
- }
593
- }
594
-
595
- var buffer = Buffer.allocUnsafe(length);
596
- var pos = 0;
597
- for (i = 0; i < list.length; ++i) {
598
- var buf = list[i];
599
- if (!internalIsBuffer(buf)) {
600
- throw new TypeError('"list" argument must be an Array of Buffers')
601
- }
602
- buf.copy(buffer, pos);
603
- pos += buf.length;
604
- }
605
- return buffer
606
- };
607
-
608
- function byteLength (string, encoding) {
609
- if (internalIsBuffer(string)) {
610
- return string.length
611
- }
612
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
613
- (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
614
- return string.byteLength
615
- }
616
- if (typeof string !== 'string') {
617
- string = '' + string;
618
- }
619
-
620
- var len = string.length;
621
- if (len === 0) return 0
622
-
623
- // Use a for loop to avoid recursion
624
- var loweredCase = false;
625
- for (;;) {
626
- switch (encoding) {
627
- case 'ascii':
628
- case 'latin1':
629
- case 'binary':
630
- return len
631
- case 'utf8':
632
- case 'utf-8':
633
- case undefined:
634
- return utf8ToBytes(string).length
635
- case 'ucs2':
636
- case 'ucs-2':
637
- case 'utf16le':
638
- case 'utf-16le':
639
- return len * 2
640
- case 'hex':
641
- return len >>> 1
642
- case 'base64':
643
- return base64ToBytes(string).length
644
- default:
645
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
646
- encoding = ('' + encoding).toLowerCase();
647
- loweredCase = true;
648
- }
649
- }
650
- }
651
- Buffer.byteLength = byteLength;
652
-
653
- function slowToString (encoding, start, end) {
654
- var loweredCase = false;
655
-
656
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
657
- // property of a typed array.
658
-
659
- // This behaves neither like String nor Uint8Array in that we set start/end
660
- // to their upper/lower bounds if the value passed is out of range.
661
- // undefined is handled specially as per ECMA-262 6th Edition,
662
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
663
- if (start === undefined || start < 0) {
664
- start = 0;
665
- }
666
- // Return early if start > this.length. Done here to prevent potential uint32
667
- // coercion fail below.
668
- if (start > this.length) {
669
- return ''
670
- }
671
-
672
- if (end === undefined || end > this.length) {
673
- end = this.length;
674
- }
675
-
676
- if (end <= 0) {
677
- return ''
678
- }
679
-
680
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
681
- end >>>= 0;
682
- start >>>= 0;
683
-
684
- if (end <= start) {
685
- return ''
686
- }
687
-
688
- if (!encoding) encoding = 'utf8';
689
-
690
- while (true) {
691
- switch (encoding) {
692
- case 'hex':
693
- return hexSlice(this, start, end)
694
-
695
- case 'utf8':
696
- case 'utf-8':
697
- return utf8Slice(this, start, end)
698
-
699
- case 'ascii':
700
- return asciiSlice(this, start, end)
701
-
702
- case 'latin1':
703
- case 'binary':
704
- return latin1Slice(this, start, end)
705
-
706
- case 'base64':
707
- return base64Slice(this, start, end)
708
-
709
- case 'ucs2':
710
- case 'ucs-2':
711
- case 'utf16le':
712
- case 'utf-16le':
713
- return utf16leSlice(this, start, end)
714
-
715
- default:
716
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
717
- encoding = (encoding + '').toLowerCase();
718
- loweredCase = true;
719
- }
720
- }
721
- }
722
-
723
- // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
724
- // Buffer instances.
725
- Buffer.prototype._isBuffer = true;
726
-
727
- function swap (b, n, m) {
728
- var i = b[n];
729
- b[n] = b[m];
730
- b[m] = i;
731
- }
732
-
733
- Buffer.prototype.swap16 = function swap16 () {
734
- var len = this.length;
735
- if (len % 2 !== 0) {
736
- throw new RangeError('Buffer size must be a multiple of 16-bits')
737
- }
738
- for (var i = 0; i < len; i += 2) {
739
- swap(this, i, i + 1);
740
- }
741
- return this
742
- };
743
-
744
- Buffer.prototype.swap32 = function swap32 () {
745
- var len = this.length;
746
- if (len % 4 !== 0) {
747
- throw new RangeError('Buffer size must be a multiple of 32-bits')
748
- }
749
- for (var i = 0; i < len; i += 4) {
750
- swap(this, i, i + 3);
751
- swap(this, i + 1, i + 2);
752
- }
753
- return this
754
- };
755
-
756
- Buffer.prototype.swap64 = function swap64 () {
757
- var len = this.length;
758
- if (len % 8 !== 0) {
759
- throw new RangeError('Buffer size must be a multiple of 64-bits')
760
- }
761
- for (var i = 0; i < len; i += 8) {
762
- swap(this, i, i + 7);
763
- swap(this, i + 1, i + 6);
764
- swap(this, i + 2, i + 5);
765
- swap(this, i + 3, i + 4);
766
- }
767
- return this
768
- };
769
-
770
- Buffer.prototype.toString = function toString () {
771
- var length = this.length | 0;
772
- if (length === 0) return ''
773
- if (arguments.length === 0) return utf8Slice(this, 0, length)
774
- return slowToString.apply(this, arguments)
775
- };
776
-
777
- Buffer.prototype.equals = function equals (b) {
778
- if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
779
- if (this === b) return true
780
- return Buffer.compare(this, b) === 0
781
- };
782
-
783
- Buffer.prototype.inspect = function inspect () {
784
- var str = '';
785
- var max = INSPECT_MAX_BYTES;
786
- if (this.length > 0) {
787
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
788
- if (this.length > max) str += ' ... ';
789
- }
790
- return '<Buffer ' + str + '>'
791
- };
792
-
793
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
794
- if (!internalIsBuffer(target)) {
795
- throw new TypeError('Argument must be a Buffer')
796
- }
797
-
798
- if (start === undefined) {
799
- start = 0;
800
- }
801
- if (end === undefined) {
802
- end = target ? target.length : 0;
803
- }
804
- if (thisStart === undefined) {
805
- thisStart = 0;
806
- }
807
- if (thisEnd === undefined) {
808
- thisEnd = this.length;
809
- }
810
-
811
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
812
- throw new RangeError('out of range index')
813
- }
814
-
815
- if (thisStart >= thisEnd && start >= end) {
816
- return 0
817
- }
818
- if (thisStart >= thisEnd) {
819
- return -1
820
- }
821
- if (start >= end) {
822
- return 1
823
- }
824
-
825
- start >>>= 0;
826
- end >>>= 0;
827
- thisStart >>>= 0;
828
- thisEnd >>>= 0;
829
-
830
- if (this === target) return 0
831
-
832
- var x = thisEnd - thisStart;
833
- var y = end - start;
834
- var len = Math.min(x, y);
835
-
836
- var thisCopy = this.slice(thisStart, thisEnd);
837
- var targetCopy = target.slice(start, end);
838
-
839
- for (var i = 0; i < len; ++i) {
840
- if (thisCopy[i] !== targetCopy[i]) {
841
- x = thisCopy[i];
842
- y = targetCopy[i];
843
- break
844
- }
845
- }
846
-
847
- if (x < y) return -1
848
- if (y < x) return 1
849
- return 0
850
- };
851
-
852
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
853
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
854
- //
855
- // Arguments:
856
- // - buffer - a Buffer to search
857
- // - val - a string, Buffer, or number
858
- // - byteOffset - an index into `buffer`; will be clamped to an int32
859
- // - encoding - an optional encoding, relevant is val is a string
860
- // - dir - true for indexOf, false for lastIndexOf
861
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
862
- // Empty buffer means no match
863
- if (buffer.length === 0) return -1
864
-
865
- // Normalize byteOffset
866
- if (typeof byteOffset === 'string') {
867
- encoding = byteOffset;
868
- byteOffset = 0;
869
- } else if (byteOffset > 0x7fffffff) {
870
- byteOffset = 0x7fffffff;
871
- } else if (byteOffset < -0x80000000) {
872
- byteOffset = -0x80000000;
873
- }
874
- byteOffset = +byteOffset; // Coerce to Number.
875
- if (isNaN(byteOffset)) {
876
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
877
- byteOffset = dir ? 0 : (buffer.length - 1);
878
- }
879
-
880
- // Normalize byteOffset: negative offsets start from the end of the buffer
881
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
882
- if (byteOffset >= buffer.length) {
883
- if (dir) return -1
884
- else byteOffset = buffer.length - 1;
885
- } else if (byteOffset < 0) {
886
- if (dir) byteOffset = 0;
887
- else return -1
888
- }
889
-
890
- // Normalize val
891
- if (typeof val === 'string') {
892
- val = Buffer.from(val, encoding);
893
- }
894
-
895
- // Finally, search either indexOf (if dir is true) or lastIndexOf
896
- if (internalIsBuffer(val)) {
897
- // Special case: looking for empty string/buffer always fails
898
- if (val.length === 0) {
899
- return -1
900
- }
901
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
902
- } else if (typeof val === 'number') {
903
- val = val & 0xFF; // Search for a byte value [0-255]
904
- if (Buffer.TYPED_ARRAY_SUPPORT &&
905
- typeof Uint8Array.prototype.indexOf === 'function') {
906
- if (dir) {
907
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
908
- } else {
909
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
910
- }
911
- }
912
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
913
- }
914
-
915
- throw new TypeError('val must be string, number or Buffer')
916
- }
917
-
918
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
919
- var indexSize = 1;
920
- var arrLength = arr.length;
921
- var valLength = val.length;
922
-
923
- if (encoding !== undefined) {
924
- encoding = String(encoding).toLowerCase();
925
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
926
- encoding === 'utf16le' || encoding === 'utf-16le') {
927
- if (arr.length < 2 || val.length < 2) {
928
- return -1
929
- }
930
- indexSize = 2;
931
- arrLength /= 2;
932
- valLength /= 2;
933
- byteOffset /= 2;
934
- }
935
- }
936
-
937
- function read (buf, i) {
938
- if (indexSize === 1) {
939
- return buf[i]
940
- } else {
941
- return buf.readUInt16BE(i * indexSize)
942
- }
943
- }
944
-
945
- var i;
946
- if (dir) {
947
- var foundIndex = -1;
948
- for (i = byteOffset; i < arrLength; i++) {
949
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
950
- if (foundIndex === -1) foundIndex = i;
951
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
952
- } else {
953
- if (foundIndex !== -1) i -= i - foundIndex;
954
- foundIndex = -1;
955
- }
956
- }
957
- } else {
958
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
959
- for (i = byteOffset; i >= 0; i--) {
960
- var found = true;
961
- for (var j = 0; j < valLength; j++) {
962
- if (read(arr, i + j) !== read(val, j)) {
963
- found = false;
964
- break
965
- }
966
- }
967
- if (found) return i
968
- }
969
- }
970
-
971
- return -1
972
- }
973
-
974
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
975
- return this.indexOf(val, byteOffset, encoding) !== -1
976
- };
977
-
978
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
979
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
980
- };
981
-
982
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
983
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
984
- };
985
-
986
- function hexWrite (buf, string, offset, length) {
987
- offset = Number(offset) || 0;
988
- var remaining = buf.length - offset;
989
- if (!length) {
990
- length = remaining;
991
- } else {
992
- length = Number(length);
993
- if (length > remaining) {
994
- length = remaining;
995
- }
996
- }
997
-
998
- // must be an even number of digits
999
- var strLen = string.length;
1000
- if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
1001
-
1002
- if (length > strLen / 2) {
1003
- length = strLen / 2;
1004
- }
1005
- for (var i = 0; i < length; ++i) {
1006
- var parsed = parseInt(string.substr(i * 2, 2), 16);
1007
- if (isNaN(parsed)) return i
1008
- buf[offset + i] = parsed;
1009
- }
1010
- return i
1011
- }
1012
-
1013
- function utf8Write (buf, string, offset, length) {
1014
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1015
- }
1016
-
1017
- function asciiWrite (buf, string, offset, length) {
1018
- return blitBuffer(asciiToBytes(string), buf, offset, length)
1019
- }
1020
-
1021
- function latin1Write (buf, string, offset, length) {
1022
- return asciiWrite(buf, string, offset, length)
1023
- }
1024
-
1025
- function base64Write (buf, string, offset, length) {
1026
- return blitBuffer(base64ToBytes(string), buf, offset, length)
1027
- }
1028
-
1029
- function ucs2Write (buf, string, offset, length) {
1030
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1031
- }
1032
-
1033
- Buffer.prototype.write = function write (string, offset, length, encoding) {
1034
- // Buffer#write(string)
1035
- if (offset === undefined) {
1036
- encoding = 'utf8';
1037
- length = this.length;
1038
- offset = 0;
1039
- // Buffer#write(string, encoding)
1040
- } else if (length === undefined && typeof offset === 'string') {
1041
- encoding = offset;
1042
- length = this.length;
1043
- offset = 0;
1044
- // Buffer#write(string, offset[, length][, encoding])
1045
- } else if (isFinite(offset)) {
1046
- offset = offset | 0;
1047
- if (isFinite(length)) {
1048
- length = length | 0;
1049
- if (encoding === undefined) encoding = 'utf8';
1050
- } else {
1051
- encoding = length;
1052
- length = undefined;
1053
- }
1054
- // legacy write(string, encoding, offset, length) - remove in v0.13
1055
- } else {
1056
- throw new Error(
1057
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1058
- )
1059
- }
1060
-
1061
- var remaining = this.length - offset;
1062
- if (length === undefined || length > remaining) length = remaining;
1063
-
1064
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1065
- throw new RangeError('Attempt to write outside buffer bounds')
1066
- }
1067
-
1068
- if (!encoding) encoding = 'utf8';
1069
-
1070
- var loweredCase = false;
1071
- for (;;) {
1072
- switch (encoding) {
1073
- case 'hex':
1074
- return hexWrite(this, string, offset, length)
1075
-
1076
- case 'utf8':
1077
- case 'utf-8':
1078
- return utf8Write(this, string, offset, length)
1079
-
1080
- case 'ascii':
1081
- return asciiWrite(this, string, offset, length)
1082
-
1083
- case 'latin1':
1084
- case 'binary':
1085
- return latin1Write(this, string, offset, length)
1086
-
1087
- case 'base64':
1088
- // Warning: maxLength not taken into account in base64Write
1089
- return base64Write(this, string, offset, length)
1090
-
1091
- case 'ucs2':
1092
- case 'ucs-2':
1093
- case 'utf16le':
1094
- case 'utf-16le':
1095
- return ucs2Write(this, string, offset, length)
1096
-
1097
- default:
1098
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1099
- encoding = ('' + encoding).toLowerCase();
1100
- loweredCase = true;
1101
- }
1102
- }
1103
- };
1104
-
1105
- Buffer.prototype.toJSON = function toJSON () {
1106
- return {
1107
- type: 'Buffer',
1108
- data: Array.prototype.slice.call(this._arr || this, 0)
1109
- }
1110
- };
1111
-
1112
- function base64Slice (buf, start, end) {
1113
- if (start === 0 && end === buf.length) {
1114
- return fromByteArray(buf)
1115
- } else {
1116
- return fromByteArray(buf.slice(start, end))
1117
- }
1118
- }
1119
-
1120
- function utf8Slice (buf, start, end) {
1121
- end = Math.min(buf.length, end);
1122
- var res = [];
1123
-
1124
- var i = start;
1125
- while (i < end) {
1126
- var firstByte = buf[i];
1127
- var codePoint = null;
1128
- var bytesPerSequence = (firstByte > 0xEF) ? 4
1129
- : (firstByte > 0xDF) ? 3
1130
- : (firstByte > 0xBF) ? 2
1131
- : 1;
1132
-
1133
- if (i + bytesPerSequence <= end) {
1134
- var secondByte, thirdByte, fourthByte, tempCodePoint;
1135
-
1136
- switch (bytesPerSequence) {
1137
- case 1:
1138
- if (firstByte < 0x80) {
1139
- codePoint = firstByte;
1140
- }
1141
- break
1142
- case 2:
1143
- secondByte = buf[i + 1];
1144
- if ((secondByte & 0xC0) === 0x80) {
1145
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1146
- if (tempCodePoint > 0x7F) {
1147
- codePoint = tempCodePoint;
1148
- }
1149
- }
1150
- break
1151
- case 3:
1152
- secondByte = buf[i + 1];
1153
- thirdByte = buf[i + 2];
1154
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1155
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1156
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1157
- codePoint = tempCodePoint;
1158
- }
1159
- }
1160
- break
1161
- case 4:
1162
- secondByte = buf[i + 1];
1163
- thirdByte = buf[i + 2];
1164
- fourthByte = buf[i + 3];
1165
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1166
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1167
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1168
- codePoint = tempCodePoint;
1169
- }
1170
- }
1171
- }
1172
- }
1173
-
1174
- if (codePoint === null) {
1175
- // we did not generate a valid codePoint so insert a
1176
- // replacement char (U+FFFD) and advance only 1 byte
1177
- codePoint = 0xFFFD;
1178
- bytesPerSequence = 1;
1179
- } else if (codePoint > 0xFFFF) {
1180
- // encode to utf16 (surrogate pair dance)
1181
- codePoint -= 0x10000;
1182
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1183
- codePoint = 0xDC00 | codePoint & 0x3FF;
1184
- }
1185
-
1186
- res.push(codePoint);
1187
- i += bytesPerSequence;
1188
- }
1189
-
1190
- return decodeCodePointsArray(res)
1191
- }
1192
-
1193
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1194
- // the lowest limit is Chrome, with 0x10000 args.
1195
- // We go 1 magnitude less, for safety
1196
- var MAX_ARGUMENTS_LENGTH = 0x1000;
1197
-
1198
- function decodeCodePointsArray (codePoints) {
1199
- var len = codePoints.length;
1200
- if (len <= MAX_ARGUMENTS_LENGTH) {
1201
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1202
- }
1203
-
1204
- // Decode in chunks to avoid "call stack size exceeded".
1205
- var res = '';
1206
- var i = 0;
1207
- while (i < len) {
1208
- res += String.fromCharCode.apply(
1209
- String,
1210
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1211
- );
1212
- }
1213
- return res
1214
- }
1215
-
1216
- function asciiSlice (buf, start, end) {
1217
- var ret = '';
1218
- end = Math.min(buf.length, end);
1219
-
1220
- for (var i = start; i < end; ++i) {
1221
- ret += String.fromCharCode(buf[i] & 0x7F);
1222
- }
1223
- return ret
1224
- }
1225
-
1226
- function latin1Slice (buf, start, end) {
1227
- var ret = '';
1228
- end = Math.min(buf.length, end);
1229
-
1230
- for (var i = start; i < end; ++i) {
1231
- ret += String.fromCharCode(buf[i]);
1232
- }
1233
- return ret
1234
- }
1235
-
1236
- function hexSlice (buf, start, end) {
1237
- var len = buf.length;
1238
-
1239
- if (!start || start < 0) start = 0;
1240
- if (!end || end < 0 || end > len) end = len;
1241
-
1242
- var out = '';
1243
- for (var i = start; i < end; ++i) {
1244
- out += toHex(buf[i]);
1245
- }
1246
- return out
1247
- }
1248
-
1249
- function utf16leSlice (buf, start, end) {
1250
- var bytes = buf.slice(start, end);
1251
- var res = '';
1252
- for (var i = 0; i < bytes.length; i += 2) {
1253
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1254
- }
1255
- return res
1256
- }
1257
-
1258
- Buffer.prototype.slice = function slice (start, end) {
1259
- var len = this.length;
1260
- start = ~~start;
1261
- end = end === undefined ? len : ~~end;
1262
-
1263
- if (start < 0) {
1264
- start += len;
1265
- if (start < 0) start = 0;
1266
- } else if (start > len) {
1267
- start = len;
1268
- }
1269
-
1270
- if (end < 0) {
1271
- end += len;
1272
- if (end < 0) end = 0;
1273
- } else if (end > len) {
1274
- end = len;
1275
- }
1276
-
1277
- if (end < start) end = start;
1278
-
1279
- var newBuf;
1280
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1281
- newBuf = this.subarray(start, end);
1282
- newBuf.__proto__ = Buffer.prototype;
1283
- } else {
1284
- var sliceLen = end - start;
1285
- newBuf = new Buffer(sliceLen, undefined);
1286
- for (var i = 0; i < sliceLen; ++i) {
1287
- newBuf[i] = this[i + start];
1288
- }
1289
- }
1290
-
1291
- return newBuf
1292
- };
1293
-
1294
- /*
1295
- * Need to make sure that buffer isn't trying to write out of bounds.
1296
- */
1297
- function checkOffset (offset, ext, length) {
1298
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1299
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1300
- }
1301
-
1302
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1303
- offset = offset | 0;
1304
- byteLength = byteLength | 0;
1305
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1306
-
1307
- var val = this[offset];
1308
- var mul = 1;
1309
- var i = 0;
1310
- while (++i < byteLength && (mul *= 0x100)) {
1311
- val += this[offset + i] * mul;
1312
- }
1313
-
1314
- return val
1315
- };
1316
-
1317
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1318
- offset = offset | 0;
1319
- byteLength = byteLength | 0;
1320
- if (!noAssert) {
1321
- checkOffset(offset, byteLength, this.length);
1322
- }
1323
-
1324
- var val = this[offset + --byteLength];
1325
- var mul = 1;
1326
- while (byteLength > 0 && (mul *= 0x100)) {
1327
- val += this[offset + --byteLength] * mul;
1328
- }
1329
-
1330
- return val
1331
- };
1332
-
1333
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1334
- if (!noAssert) checkOffset(offset, 1, this.length);
1335
- return this[offset]
1336
- };
1337
-
1338
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1339
- if (!noAssert) checkOffset(offset, 2, this.length);
1340
- return this[offset] | (this[offset + 1] << 8)
1341
- };
1342
-
1343
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1344
- if (!noAssert) checkOffset(offset, 2, this.length);
1345
- return (this[offset] << 8) | this[offset + 1]
1346
- };
1347
-
1348
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1349
- if (!noAssert) checkOffset(offset, 4, this.length);
1350
-
1351
- return ((this[offset]) |
1352
- (this[offset + 1] << 8) |
1353
- (this[offset + 2] << 16)) +
1354
- (this[offset + 3] * 0x1000000)
1355
- };
1356
-
1357
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1358
- if (!noAssert) checkOffset(offset, 4, this.length);
1359
-
1360
- return (this[offset] * 0x1000000) +
1361
- ((this[offset + 1] << 16) |
1362
- (this[offset + 2] << 8) |
1363
- this[offset + 3])
1364
- };
1365
-
1366
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1367
- offset = offset | 0;
1368
- byteLength = byteLength | 0;
1369
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1370
-
1371
- var val = this[offset];
1372
- var mul = 1;
1373
- var i = 0;
1374
- while (++i < byteLength && (mul *= 0x100)) {
1375
- val += this[offset + i] * mul;
1376
- }
1377
- mul *= 0x80;
1378
-
1379
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1380
-
1381
- return val
1382
- };
1383
-
1384
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1385
- offset = offset | 0;
1386
- byteLength = byteLength | 0;
1387
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1388
-
1389
- var i = byteLength;
1390
- var mul = 1;
1391
- var val = this[offset + --i];
1392
- while (i > 0 && (mul *= 0x100)) {
1393
- val += this[offset + --i] * mul;
1394
- }
1395
- mul *= 0x80;
1396
-
1397
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1398
-
1399
- return val
1400
- };
1401
-
1402
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1403
- if (!noAssert) checkOffset(offset, 1, this.length);
1404
- if (!(this[offset] & 0x80)) return (this[offset])
1405
- return ((0xff - this[offset] + 1) * -1)
1406
- };
1407
-
1408
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1409
- if (!noAssert) checkOffset(offset, 2, this.length);
1410
- var val = this[offset] | (this[offset + 1] << 8);
1411
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1412
- };
1413
-
1414
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1415
- if (!noAssert) checkOffset(offset, 2, this.length);
1416
- var val = this[offset + 1] | (this[offset] << 8);
1417
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1418
- };
1419
-
1420
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1421
- if (!noAssert) checkOffset(offset, 4, this.length);
1422
-
1423
- return (this[offset]) |
1424
- (this[offset + 1] << 8) |
1425
- (this[offset + 2] << 16) |
1426
- (this[offset + 3] << 24)
1427
- };
1428
-
1429
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1430
- if (!noAssert) checkOffset(offset, 4, this.length);
1431
-
1432
- return (this[offset] << 24) |
1433
- (this[offset + 1] << 16) |
1434
- (this[offset + 2] << 8) |
1435
- (this[offset + 3])
1436
- };
1437
-
1438
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1439
- if (!noAssert) checkOffset(offset, 4, this.length);
1440
- return read(this, offset, true, 23, 4)
1441
- };
1442
-
1443
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1444
- if (!noAssert) checkOffset(offset, 4, this.length);
1445
- return read(this, offset, false, 23, 4)
1446
- };
1447
-
1448
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1449
- if (!noAssert) checkOffset(offset, 8, this.length);
1450
- return read(this, offset, true, 52, 8)
1451
- };
1452
-
1453
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1454
- if (!noAssert) checkOffset(offset, 8, this.length);
1455
- return read(this, offset, false, 52, 8)
1456
- };
1457
-
1458
- function checkInt (buf, value, offset, ext, max, min) {
1459
- if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1460
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1461
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1462
- }
1463
-
1464
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1465
- value = +value;
1466
- offset = offset | 0;
1467
- byteLength = byteLength | 0;
1468
- if (!noAssert) {
1469
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1470
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1471
- }
1472
-
1473
- var mul = 1;
1474
- var i = 0;
1475
- this[offset] = value & 0xFF;
1476
- while (++i < byteLength && (mul *= 0x100)) {
1477
- this[offset + i] = (value / mul) & 0xFF;
1478
- }
1479
-
1480
- return offset + byteLength
1481
- };
1482
-
1483
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1484
- value = +value;
1485
- offset = offset | 0;
1486
- byteLength = byteLength | 0;
1487
- if (!noAssert) {
1488
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1489
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1490
- }
1491
-
1492
- var i = byteLength - 1;
1493
- var mul = 1;
1494
- this[offset + i] = value & 0xFF;
1495
- while (--i >= 0 && (mul *= 0x100)) {
1496
- this[offset + i] = (value / mul) & 0xFF;
1497
- }
1498
-
1499
- return offset + byteLength
1500
- };
1501
-
1502
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1503
- value = +value;
1504
- offset = offset | 0;
1505
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1506
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1507
- this[offset] = (value & 0xff);
1508
- return offset + 1
1509
- };
1510
-
1511
- function objectWriteUInt16 (buf, value, offset, littleEndian) {
1512
- if (value < 0) value = 0xffff + value + 1;
1513
- for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1514
- buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1515
- (littleEndian ? i : 1 - i) * 8;
1516
- }
1517
- }
1518
-
1519
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1520
- value = +value;
1521
- offset = offset | 0;
1522
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1523
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1524
- this[offset] = (value & 0xff);
1525
- this[offset + 1] = (value >>> 8);
1526
- } else {
1527
- objectWriteUInt16(this, value, offset, true);
1528
- }
1529
- return offset + 2
1530
- };
1531
-
1532
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1533
- value = +value;
1534
- offset = offset | 0;
1535
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1536
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1537
- this[offset] = (value >>> 8);
1538
- this[offset + 1] = (value & 0xff);
1539
- } else {
1540
- objectWriteUInt16(this, value, offset, false);
1541
- }
1542
- return offset + 2
1543
- };
1544
-
1545
- function objectWriteUInt32 (buf, value, offset, littleEndian) {
1546
- if (value < 0) value = 0xffffffff + value + 1;
1547
- for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1548
- buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
1549
- }
1550
- }
1551
-
1552
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1553
- value = +value;
1554
- offset = offset | 0;
1555
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1556
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1557
- this[offset + 3] = (value >>> 24);
1558
- this[offset + 2] = (value >>> 16);
1559
- this[offset + 1] = (value >>> 8);
1560
- this[offset] = (value & 0xff);
1561
- } else {
1562
- objectWriteUInt32(this, value, offset, true);
1563
- }
1564
- return offset + 4
1565
- };
1566
-
1567
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1568
- value = +value;
1569
- offset = offset | 0;
1570
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1571
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1572
- this[offset] = (value >>> 24);
1573
- this[offset + 1] = (value >>> 16);
1574
- this[offset + 2] = (value >>> 8);
1575
- this[offset + 3] = (value & 0xff);
1576
- } else {
1577
- objectWriteUInt32(this, value, offset, false);
1578
- }
1579
- return offset + 4
1580
- };
1581
-
1582
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1583
- value = +value;
1584
- offset = offset | 0;
1585
- if (!noAssert) {
1586
- var limit = Math.pow(2, 8 * byteLength - 1);
1587
-
1588
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1589
- }
1590
-
1591
- var i = 0;
1592
- var mul = 1;
1593
- var sub = 0;
1594
- this[offset] = value & 0xFF;
1595
- while (++i < byteLength && (mul *= 0x100)) {
1596
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1597
- sub = 1;
1598
- }
1599
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1600
- }
1601
-
1602
- return offset + byteLength
1603
- };
1604
-
1605
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1606
- value = +value;
1607
- offset = offset | 0;
1608
- if (!noAssert) {
1609
- var limit = Math.pow(2, 8 * byteLength - 1);
1610
-
1611
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1612
- }
1613
-
1614
- var i = byteLength - 1;
1615
- var mul = 1;
1616
- var sub = 0;
1617
- this[offset + i] = value & 0xFF;
1618
- while (--i >= 0 && (mul *= 0x100)) {
1619
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1620
- sub = 1;
1621
- }
1622
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1623
- }
1624
-
1625
- return offset + byteLength
1626
- };
1627
-
1628
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1629
- value = +value;
1630
- offset = offset | 0;
1631
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
1632
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1633
- if (value < 0) value = 0xff + value + 1;
1634
- this[offset] = (value & 0xff);
1635
- return offset + 1
1636
- };
1637
-
1638
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1639
- value = +value;
1640
- offset = offset | 0;
1641
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1642
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1643
- this[offset] = (value & 0xff);
1644
- this[offset + 1] = (value >>> 8);
1645
- } else {
1646
- objectWriteUInt16(this, value, offset, true);
1647
- }
1648
- return offset + 2
1649
- };
1650
-
1651
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1652
- value = +value;
1653
- offset = offset | 0;
1654
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1655
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1656
- this[offset] = (value >>> 8);
1657
- this[offset + 1] = (value & 0xff);
1658
- } else {
1659
- objectWriteUInt16(this, value, offset, false);
1660
- }
1661
- return offset + 2
1662
- };
1663
-
1664
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1665
- value = +value;
1666
- offset = offset | 0;
1667
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1668
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1669
- this[offset] = (value & 0xff);
1670
- this[offset + 1] = (value >>> 8);
1671
- this[offset + 2] = (value >>> 16);
1672
- this[offset + 3] = (value >>> 24);
1673
- } else {
1674
- objectWriteUInt32(this, value, offset, true);
1675
- }
1676
- return offset + 4
1677
- };
1678
-
1679
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1680
- value = +value;
1681
- offset = offset | 0;
1682
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1683
- if (value < 0) value = 0xffffffff + value + 1;
1684
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1685
- this[offset] = (value >>> 24);
1686
- this[offset + 1] = (value >>> 16);
1687
- this[offset + 2] = (value >>> 8);
1688
- this[offset + 3] = (value & 0xff);
1689
- } else {
1690
- objectWriteUInt32(this, value, offset, false);
1691
- }
1692
- return offset + 4
1693
- };
1694
-
1695
- function checkIEEE754 (buf, value, offset, ext, max, min) {
1696
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1697
- if (offset < 0) throw new RangeError('Index out of range')
1698
- }
1699
-
1700
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
1701
- if (!noAssert) {
1702
- checkIEEE754(buf, value, offset, 4);
1703
- }
1704
- write(buf, value, offset, littleEndian, 23, 4);
1705
- return offset + 4
1706
- }
1707
-
1708
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1709
- return writeFloat(this, value, offset, true, noAssert)
1710
- };
1711
-
1712
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1713
- return writeFloat(this, value, offset, false, noAssert)
1714
- };
1715
-
1716
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
1717
- if (!noAssert) {
1718
- checkIEEE754(buf, value, offset, 8);
1719
- }
1720
- write(buf, value, offset, littleEndian, 52, 8);
1721
- return offset + 8
1722
- }
1723
-
1724
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1725
- return writeDouble(this, value, offset, true, noAssert)
1726
- };
1727
-
1728
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1729
- return writeDouble(this, value, offset, false, noAssert)
1730
- };
1731
-
1732
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1733
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1734
- if (!start) start = 0;
1735
- if (!end && end !== 0) end = this.length;
1736
- if (targetStart >= target.length) targetStart = target.length;
1737
- if (!targetStart) targetStart = 0;
1738
- if (end > 0 && end < start) end = start;
1739
-
1740
- // Copy 0 bytes; we're done
1741
- if (end === start) return 0
1742
- if (target.length === 0 || this.length === 0) return 0
1743
-
1744
- // Fatal error conditions
1745
- if (targetStart < 0) {
1746
- throw new RangeError('targetStart out of bounds')
1747
- }
1748
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1749
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
1750
-
1751
- // Are we oob?
1752
- if (end > this.length) end = this.length;
1753
- if (target.length - targetStart < end - start) {
1754
- end = target.length - targetStart + start;
1755
- }
1756
-
1757
- var len = end - start;
1758
- var i;
1759
-
1760
- if (this === target && start < targetStart && targetStart < end) {
1761
- // descending copy from end
1762
- for (i = len - 1; i >= 0; --i) {
1763
- target[i + targetStart] = this[i + start];
1764
- }
1765
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1766
- // ascending copy from start
1767
- for (i = 0; i < len; ++i) {
1768
- target[i + targetStart] = this[i + start];
1769
- }
1770
- } else {
1771
- Uint8Array.prototype.set.call(
1772
- target,
1773
- this.subarray(start, start + len),
1774
- targetStart
1775
- );
1776
- }
1777
-
1778
- return len
1779
- };
1780
-
1781
- // Usage:
1782
- // buffer.fill(number[, offset[, end]])
1783
- // buffer.fill(buffer[, offset[, end]])
1784
- // buffer.fill(string[, offset[, end]][, encoding])
1785
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
1786
- // Handle string cases:
1787
- if (typeof val === 'string') {
1788
- if (typeof start === 'string') {
1789
- encoding = start;
1790
- start = 0;
1791
- end = this.length;
1792
- } else if (typeof end === 'string') {
1793
- encoding = end;
1794
- end = this.length;
1795
- }
1796
- if (val.length === 1) {
1797
- var code = val.charCodeAt(0);
1798
- if (code < 256) {
1799
- val = code;
1800
- }
1801
- }
1802
- if (encoding !== undefined && typeof encoding !== 'string') {
1803
- throw new TypeError('encoding must be a string')
1804
- }
1805
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1806
- throw new TypeError('Unknown encoding: ' + encoding)
1807
- }
1808
- } else if (typeof val === 'number') {
1809
- val = val & 255;
1810
- }
1811
-
1812
- // Invalid ranges are not set to a default, so can range check early.
1813
- if (start < 0 || this.length < start || this.length < end) {
1814
- throw new RangeError('Out of range index')
1815
- }
1816
-
1817
- if (end <= start) {
1818
- return this
1819
- }
1820
-
1821
- start = start >>> 0;
1822
- end = end === undefined ? this.length : end >>> 0;
1823
-
1824
- if (!val) val = 0;
1825
-
1826
- var i;
1827
- if (typeof val === 'number') {
1828
- for (i = start; i < end; ++i) {
1829
- this[i] = val;
1830
- }
1831
- } else {
1832
- var bytes = internalIsBuffer(val)
1833
- ? val
1834
- : utf8ToBytes(new Buffer(val, encoding).toString());
1835
- var len = bytes.length;
1836
- for (i = 0; i < end - start; ++i) {
1837
- this[i + start] = bytes[i % len];
1838
- }
1839
- }
1840
-
1841
- return this
1842
- };
1843
-
1844
- // HELPER FUNCTIONS
1845
- // ================
1846
-
1847
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
1848
-
1849
- function base64clean (str) {
1850
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
1851
- str = stringtrim(str).replace(INVALID_BASE64_RE, '');
1852
- // Node converts strings with length < 2 to ''
1853
- if (str.length < 2) return ''
1854
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1855
- while (str.length % 4 !== 0) {
1856
- str = str + '=';
1857
- }
1858
- return str
1859
- }
1860
-
1861
- function stringtrim (str) {
1862
- if (str.trim) return str.trim()
1863
- return str.replace(/^\s+|\s+$/g, '')
1864
- }
1865
-
1866
- function toHex (n) {
1867
- if (n < 16) return '0' + n.toString(16)
1868
- return n.toString(16)
1869
- }
1870
-
1871
- function utf8ToBytes (string, units) {
1872
- units = units || Infinity;
1873
- var codePoint;
1874
- var length = string.length;
1875
- var leadSurrogate = null;
1876
- var bytes = [];
1877
-
1878
- for (var i = 0; i < length; ++i) {
1879
- codePoint = string.charCodeAt(i);
1880
-
1881
- // is surrogate component
1882
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
1883
- // last char was a lead
1884
- if (!leadSurrogate) {
1885
- // no lead yet
1886
- if (codePoint > 0xDBFF) {
1887
- // unexpected trail
1888
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1889
- continue
1890
- } else if (i + 1 === length) {
1891
- // unpaired lead
1892
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1893
- continue
1894
- }
1895
-
1896
- // valid lead
1897
- leadSurrogate = codePoint;
1898
-
1899
- continue
1900
- }
1901
-
1902
- // 2 leads in a row
1903
- if (codePoint < 0xDC00) {
1904
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1905
- leadSurrogate = codePoint;
1906
- continue
1907
- }
1908
-
1909
- // valid surrogate pair
1910
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
1911
- } else if (leadSurrogate) {
1912
- // valid bmp char, but last char was a lead
1913
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1914
- }
1915
-
1916
- leadSurrogate = null;
1917
-
1918
- // encode utf8
1919
- if (codePoint < 0x80) {
1920
- if ((units -= 1) < 0) break
1921
- bytes.push(codePoint);
1922
- } else if (codePoint < 0x800) {
1923
- if ((units -= 2) < 0) break
1924
- bytes.push(
1925
- codePoint >> 0x6 | 0xC0,
1926
- codePoint & 0x3F | 0x80
1927
- );
1928
- } else if (codePoint < 0x10000) {
1929
- if ((units -= 3) < 0) break
1930
- bytes.push(
1931
- codePoint >> 0xC | 0xE0,
1932
- codePoint >> 0x6 & 0x3F | 0x80,
1933
- codePoint & 0x3F | 0x80
1934
- );
1935
- } else if (codePoint < 0x110000) {
1936
- if ((units -= 4) < 0) break
1937
- bytes.push(
1938
- codePoint >> 0x12 | 0xF0,
1939
- codePoint >> 0xC & 0x3F | 0x80,
1940
- codePoint >> 0x6 & 0x3F | 0x80,
1941
- codePoint & 0x3F | 0x80
1942
- );
1943
- } else {
1944
- throw new Error('Invalid code point')
1945
- }
1946
- }
1947
-
1948
- return bytes
1949
- }
1950
-
1951
- function asciiToBytes (str) {
1952
- var byteArray = [];
1953
- for (var i = 0; i < str.length; ++i) {
1954
- // Node's code seems to be doing this and not & 0x7F..
1955
- byteArray.push(str.charCodeAt(i) & 0xFF);
1956
- }
1957
- return byteArray
1958
- }
1959
-
1960
- function utf16leToBytes (str, units) {
1961
- var c, hi, lo;
1962
- var byteArray = [];
1963
- for (var i = 0; i < str.length; ++i) {
1964
- if ((units -= 2) < 0) break
1965
-
1966
- c = str.charCodeAt(i);
1967
- hi = c >> 8;
1968
- lo = c % 256;
1969
- byteArray.push(lo);
1970
- byteArray.push(hi);
1971
- }
1972
-
1973
- return byteArray
1974
- }
1975
-
1976
-
1977
- function base64ToBytes (str) {
1978
- return toByteArray(base64clean(str))
1979
- }
1980
-
1981
- function blitBuffer (src, dst, offset, length) {
1982
- for (var i = 0; i < length; ++i) {
1983
- if ((i + offset >= dst.length) || (i >= src.length)) break
1984
- dst[i + offset] = src[i];
1985
- }
1986
- return i
1987
- }
1988
-
1989
- function isnan (val) {
1990
- return val !== val // eslint-disable-line no-self-compare
1991
- }
1992
-
1993
-
1994
- // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
1995
- // The _isBuffer check is for Safari 5-7 support, because it's missing
1996
- // Object.prototype.constructor. Remove this eventually
1997
- function isBuffer(obj) {
1998
- return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
1999
- }
2000
-
2001
- function isFastBuffer (obj) {
2002
- return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
2003
- }
2004
-
2005
- // For Node v0.10 support. Remove this eventually.
2006
- function isSlowBuffer (obj) {
2007
- return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
2008
- }
2009
-
2010
- export { Buffer as B, getDefaultExportFromCjs as a, commonjsGlobal as b, createCommonjsModule as c, commonjsRequire as d, getAugmentedNamespace as g, process_1 as p };