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