adofai 2.9.13 → 2.9.14

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