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