@gcorevideo/player 0.0.2 → 0.0.4
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.
- package/dist/DashPlayback-BRJzl8D8.js +901 -0
- package/dist/{HlsPlayback-Avwy8-0O.js → HlsPlayback-D9EmONbV.js} +25 -27
- package/dist/index-C02TmVOf.js +41012 -0
- package/dist/index.js +1 -4
- package/package.json +1 -2
- package/rollup.config.js +1 -3
- package/dist/DashPlayback-6wKK0_pL.js +0 -666
- package/dist/DashPlayback-8U6_s4Jc.js +0 -666
- package/dist/DashPlayback-BeZz7mN9.js +0 -663
- package/dist/DashPlayback-CRdja67F.js +0 -667
- package/dist/DashPlayback-D0df6zGg.js +0 -663
- package/dist/DashPlayback-D7egS-CZ.js +0 -664
- package/dist/DashPlayback-DH5lZMRR.js +0 -663
- package/dist/DashPlayback-DZfIc9sK.js +0 -665
- package/dist/DashPlayback-VhCxbQhn.js +0 -666
- package/dist/DashPlayback-oVlZkeUP.js +0 -662
- package/dist/HlsPlayback-CYDGVQC4.js +0 -750
- package/dist/index-DTOY9tbl.js +0 -3332
package/dist/index-DTOY9tbl.js
DELETED
|
@@ -1,3332 +0,0 @@
|
|
|
1
|
-
import { $, Log, Loader, Player as Player$1, Browser } from '@clappr/core';
|
|
2
|
-
import HLSJS from 'hls.js';
|
|
3
|
-
import EventLite from 'event-lite';
|
|
4
|
-
|
|
5
|
-
const global$1 = (typeof global !== "undefined" ? global :
|
|
6
|
-
typeof self !== "undefined" ? self :
|
|
7
|
-
typeof window !== "undefined" ? window : {});
|
|
8
|
-
|
|
9
|
-
var lookup = [];
|
|
10
|
-
var revLookup = [];
|
|
11
|
-
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
12
|
-
var inited = false;
|
|
13
|
-
function init () {
|
|
14
|
-
inited = true;
|
|
15
|
-
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
16
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
|
17
|
-
lookup[i] = code[i];
|
|
18
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
revLookup['-'.charCodeAt(0)] = 62;
|
|
22
|
-
revLookup['_'.charCodeAt(0)] = 63;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function toByteArray (b64) {
|
|
26
|
-
if (!inited) {
|
|
27
|
-
init();
|
|
28
|
-
}
|
|
29
|
-
var i, j, l, tmp, placeHolders, arr;
|
|
30
|
-
var len = b64.length;
|
|
31
|
-
|
|
32
|
-
if (len % 4 > 0) {
|
|
33
|
-
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// the number of equal signs (place holders)
|
|
37
|
-
// if there are two placeholders, than the two characters before it
|
|
38
|
-
// represent one byte
|
|
39
|
-
// if there is only one, then the three characters before it represent 2 bytes
|
|
40
|
-
// this is just a cheap hack to not do indexOf twice
|
|
41
|
-
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
|
|
42
|
-
|
|
43
|
-
// base64 is 4/3 + up to two characters of the original data
|
|
44
|
-
arr = new Arr(len * 3 / 4 - placeHolders);
|
|
45
|
-
|
|
46
|
-
// if there are placeholders, only get up to the last complete 4 chars
|
|
47
|
-
l = placeHolders > 0 ? len - 4 : len;
|
|
48
|
-
|
|
49
|
-
var L = 0;
|
|
50
|
-
|
|
51
|
-
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
52
|
-
tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
|
|
53
|
-
arr[L++] = (tmp >> 16) & 0xFF;
|
|
54
|
-
arr[L++] = (tmp >> 8) & 0xFF;
|
|
55
|
-
arr[L++] = tmp & 0xFF;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (placeHolders === 2) {
|
|
59
|
-
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
60
|
-
arr[L++] = tmp & 0xFF;
|
|
61
|
-
} else if (placeHolders === 1) {
|
|
62
|
-
tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
63
|
-
arr[L++] = (tmp >> 8) & 0xFF;
|
|
64
|
-
arr[L++] = tmp & 0xFF;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return arr
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function tripletToBase64 (num) {
|
|
71
|
-
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function encodeChunk (uint8, start, end) {
|
|
75
|
-
var tmp;
|
|
76
|
-
var output = [];
|
|
77
|
-
for (var i = start; i < end; i += 3) {
|
|
78
|
-
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
79
|
-
output.push(tripletToBase64(tmp));
|
|
80
|
-
}
|
|
81
|
-
return output.join('')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function fromByteArray (uint8) {
|
|
85
|
-
if (!inited) {
|
|
86
|
-
init();
|
|
87
|
-
}
|
|
88
|
-
var tmp;
|
|
89
|
-
var len = uint8.length;
|
|
90
|
-
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
91
|
-
var output = '';
|
|
92
|
-
var parts = [];
|
|
93
|
-
var maxChunkLength = 16383; // must be multiple of 3
|
|
94
|
-
|
|
95
|
-
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
96
|
-
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
97
|
-
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
101
|
-
if (extraBytes === 1) {
|
|
102
|
-
tmp = uint8[len - 1];
|
|
103
|
-
output += lookup[tmp >> 2];
|
|
104
|
-
output += lookup[(tmp << 4) & 0x3F];
|
|
105
|
-
output += '==';
|
|
106
|
-
} else if (extraBytes === 2) {
|
|
107
|
-
tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
|
|
108
|
-
output += lookup[tmp >> 10];
|
|
109
|
-
output += lookup[(tmp >> 4) & 0x3F];
|
|
110
|
-
output += lookup[(tmp << 2) & 0x3F];
|
|
111
|
-
output += '=';
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
parts.push(output);
|
|
115
|
-
|
|
116
|
-
return parts.join('')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function read (buffer, offset, isLE, mLen, nBytes) {
|
|
120
|
-
var e, m;
|
|
121
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
122
|
-
var eMax = (1 << eLen) - 1;
|
|
123
|
-
var eBias = eMax >> 1;
|
|
124
|
-
var nBits = -7;
|
|
125
|
-
var i = isLE ? (nBytes - 1) : 0;
|
|
126
|
-
var d = isLE ? -1 : 1;
|
|
127
|
-
var s = buffer[offset + i];
|
|
128
|
-
|
|
129
|
-
i += d;
|
|
130
|
-
|
|
131
|
-
e = s & ((1 << (-nBits)) - 1);
|
|
132
|
-
s >>= (-nBits);
|
|
133
|
-
nBits += eLen;
|
|
134
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
135
|
-
|
|
136
|
-
m = e & ((1 << (-nBits)) - 1);
|
|
137
|
-
e >>= (-nBits);
|
|
138
|
-
nBits += mLen;
|
|
139
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
140
|
-
|
|
141
|
-
if (e === 0) {
|
|
142
|
-
e = 1 - eBias;
|
|
143
|
-
} else if (e === eMax) {
|
|
144
|
-
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
145
|
-
} else {
|
|
146
|
-
m = m + Math.pow(2, mLen);
|
|
147
|
-
e = e - eBias;
|
|
148
|
-
}
|
|
149
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function write (buffer, value, offset, isLE, mLen, nBytes) {
|
|
153
|
-
var e, m, c;
|
|
154
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
155
|
-
var eMax = (1 << eLen) - 1;
|
|
156
|
-
var eBias = eMax >> 1;
|
|
157
|
-
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
158
|
-
var i = isLE ? 0 : (nBytes - 1);
|
|
159
|
-
var d = isLE ? 1 : -1;
|
|
160
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
161
|
-
|
|
162
|
-
value = Math.abs(value);
|
|
163
|
-
|
|
164
|
-
if (isNaN(value) || value === Infinity) {
|
|
165
|
-
m = isNaN(value) ? 1 : 0;
|
|
166
|
-
e = eMax;
|
|
167
|
-
} else {
|
|
168
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
169
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
170
|
-
e--;
|
|
171
|
-
c *= 2;
|
|
172
|
-
}
|
|
173
|
-
if (e + eBias >= 1) {
|
|
174
|
-
value += rt / c;
|
|
175
|
-
} else {
|
|
176
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
177
|
-
}
|
|
178
|
-
if (value * c >= 2) {
|
|
179
|
-
e++;
|
|
180
|
-
c /= 2;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (e + eBias >= eMax) {
|
|
184
|
-
m = 0;
|
|
185
|
-
e = eMax;
|
|
186
|
-
} else if (e + eBias >= 1) {
|
|
187
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
188
|
-
e = e + eBias;
|
|
189
|
-
} else {
|
|
190
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
191
|
-
e = 0;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
196
|
-
|
|
197
|
-
e = (e << mLen) | m;
|
|
198
|
-
eLen += mLen;
|
|
199
|
-
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
200
|
-
|
|
201
|
-
buffer[offset + i - d] |= s * 128;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
var toString = {}.toString;
|
|
205
|
-
|
|
206
|
-
var isArray$1 = Array.isArray || function (arr) {
|
|
207
|
-
return toString.call(arr) == '[object Array]';
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
/*!
|
|
211
|
-
* The buffer module from node.js, for the browser.
|
|
212
|
-
*
|
|
213
|
-
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
214
|
-
* @license MIT
|
|
215
|
-
*/
|
|
216
|
-
/* eslint-disable no-proto */
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
var INSPECT_MAX_BYTES = 50;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
223
|
-
* === true Use Uint8Array implementation (fastest)
|
|
224
|
-
* === false Use Object implementation (most compatible, even IE6)
|
|
225
|
-
*
|
|
226
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
227
|
-
* Opera 11.6+, iOS 4.2+.
|
|
228
|
-
*
|
|
229
|
-
* Due to various browser bugs, sometimes the Object implementation will be used even
|
|
230
|
-
* when the browser supports typed arrays.
|
|
231
|
-
*
|
|
232
|
-
* Note:
|
|
233
|
-
*
|
|
234
|
-
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
|
235
|
-
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
|
236
|
-
*
|
|
237
|
-
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
|
238
|
-
*
|
|
239
|
-
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
|
240
|
-
* incorrect length in some situations.
|
|
241
|
-
|
|
242
|
-
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
|
243
|
-
* get the Object implementation, which is slower but behaves correctly.
|
|
244
|
-
*/
|
|
245
|
-
Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
|
|
246
|
-
? global$1.TYPED_ARRAY_SUPPORT
|
|
247
|
-
: true;
|
|
248
|
-
|
|
249
|
-
/*
|
|
250
|
-
* Export kMaxLength after typed array support is determined.
|
|
251
|
-
*/
|
|
252
|
-
kMaxLength();
|
|
253
|
-
|
|
254
|
-
function kMaxLength () {
|
|
255
|
-
return Buffer.TYPED_ARRAY_SUPPORT
|
|
256
|
-
? 0x7fffffff
|
|
257
|
-
: 0x3fffffff
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function createBuffer (that, length) {
|
|
261
|
-
if (kMaxLength() < length) {
|
|
262
|
-
throw new RangeError('Invalid typed array length')
|
|
263
|
-
}
|
|
264
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
265
|
-
// Return an augmented `Uint8Array` instance, for best performance
|
|
266
|
-
that = new Uint8Array(length);
|
|
267
|
-
that.__proto__ = Buffer.prototype;
|
|
268
|
-
} else {
|
|
269
|
-
// Fallback: Return an object instance of the Buffer class
|
|
270
|
-
if (that === null) {
|
|
271
|
-
that = new Buffer(length);
|
|
272
|
-
}
|
|
273
|
-
that.length = length;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return that
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
281
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
282
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
283
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
284
|
-
* returns a single octet.
|
|
285
|
-
*
|
|
286
|
-
* The `Uint8Array` prototype remains unmodified.
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
|
-
function Buffer (arg, encodingOrOffset, length) {
|
|
290
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
|
|
291
|
-
return new Buffer(arg, encodingOrOffset, length)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Common case.
|
|
295
|
-
if (typeof arg === 'number') {
|
|
296
|
-
if (typeof encodingOrOffset === 'string') {
|
|
297
|
-
throw new Error(
|
|
298
|
-
'If encoding is specified then the first argument must be a string'
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
return allocUnsafe(this, arg)
|
|
302
|
-
}
|
|
303
|
-
return from(this, arg, encodingOrOffset, length)
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
Buffer.poolSize = 8192; // not used by this implementation
|
|
307
|
-
|
|
308
|
-
// TODO: Legacy, not needed anymore. Remove in next major version.
|
|
309
|
-
Buffer._augment = function (arr) {
|
|
310
|
-
arr.__proto__ = Buffer.prototype;
|
|
311
|
-
return arr
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
function from (that, value, encodingOrOffset, length) {
|
|
315
|
-
if (typeof value === 'number') {
|
|
316
|
-
throw new TypeError('"value" argument must not be a number')
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
|
320
|
-
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (typeof value === 'string') {
|
|
324
|
-
return fromString(that, value, encodingOrOffset)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return fromObject(that, value)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
332
|
-
* if value is a number.
|
|
333
|
-
* Buffer.from(str[, encoding])
|
|
334
|
-
* Buffer.from(array)
|
|
335
|
-
* Buffer.from(buffer)
|
|
336
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
337
|
-
**/
|
|
338
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
|
339
|
-
return from(null, value, encodingOrOffset, length)
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
343
|
-
Buffer.prototype.__proto__ = Uint8Array.prototype;
|
|
344
|
-
Buffer.__proto__ = Uint8Array;
|
|
345
|
-
if (typeof Symbol !== 'undefined' && Symbol.species &&
|
|
346
|
-
Buffer[Symbol.species] === Buffer) ;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function assertSize (size) {
|
|
350
|
-
if (typeof size !== 'number') {
|
|
351
|
-
throw new TypeError('"size" argument must be a number')
|
|
352
|
-
} else if (size < 0) {
|
|
353
|
-
throw new RangeError('"size" argument must not be negative')
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function alloc (that, size, fill, encoding) {
|
|
358
|
-
assertSize(size);
|
|
359
|
-
if (size <= 0) {
|
|
360
|
-
return createBuffer(that, size)
|
|
361
|
-
}
|
|
362
|
-
if (fill !== undefined) {
|
|
363
|
-
// Only pay attention to encoding if it's a string. This
|
|
364
|
-
// prevents accidentally sending in a number that would
|
|
365
|
-
// be interpretted as a start offset.
|
|
366
|
-
return typeof encoding === 'string'
|
|
367
|
-
? createBuffer(that, size).fill(fill, encoding)
|
|
368
|
-
: createBuffer(that, size).fill(fill)
|
|
369
|
-
}
|
|
370
|
-
return createBuffer(that, size)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Creates a new filled Buffer instance.
|
|
375
|
-
* alloc(size[, fill[, encoding]])
|
|
376
|
-
**/
|
|
377
|
-
Buffer.alloc = function (size, fill, encoding) {
|
|
378
|
-
return alloc(null, size, fill, encoding)
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
function allocUnsafe (that, size) {
|
|
382
|
-
assertSize(size);
|
|
383
|
-
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
|
|
384
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
|
385
|
-
for (var i = 0; i < size; ++i) {
|
|
386
|
-
that[i] = 0;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return that
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
394
|
-
* */
|
|
395
|
-
Buffer.allocUnsafe = function (size) {
|
|
396
|
-
return allocUnsafe(null, size)
|
|
397
|
-
};
|
|
398
|
-
/**
|
|
399
|
-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
400
|
-
*/
|
|
401
|
-
Buffer.allocUnsafeSlow = function (size) {
|
|
402
|
-
return allocUnsafe(null, size)
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
function fromString (that, string, encoding) {
|
|
406
|
-
if (typeof encoding !== 'string' || encoding === '') {
|
|
407
|
-
encoding = 'utf8';
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (!Buffer.isEncoding(encoding)) {
|
|
411
|
-
throw new TypeError('"encoding" must be a valid string encoding')
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
var length = byteLength(string, encoding) | 0;
|
|
415
|
-
that = createBuffer(that, length);
|
|
416
|
-
|
|
417
|
-
var actual = that.write(string, encoding);
|
|
418
|
-
|
|
419
|
-
if (actual !== length) {
|
|
420
|
-
// Writing a hex string, for example, that contains invalid characters will
|
|
421
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
|
422
|
-
// 'abxxcd' will be treated as 'ab')
|
|
423
|
-
that = that.slice(0, actual);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return that
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function fromArrayLike (that, array) {
|
|
430
|
-
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
431
|
-
that = createBuffer(that, length);
|
|
432
|
-
for (var i = 0; i < length; i += 1) {
|
|
433
|
-
that[i] = array[i] & 255;
|
|
434
|
-
}
|
|
435
|
-
return that
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function fromArrayBuffer (that, array, byteOffset, length) {
|
|
439
|
-
array.byteLength; // this throws if `array` is not a valid ArrayBuffer
|
|
440
|
-
|
|
441
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
442
|
-
throw new RangeError('\'offset\' is out of bounds')
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
446
|
-
throw new RangeError('\'length\' is out of bounds')
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (byteOffset === undefined && length === undefined) {
|
|
450
|
-
array = new Uint8Array(array);
|
|
451
|
-
} else if (length === undefined) {
|
|
452
|
-
array = new Uint8Array(array, byteOffset);
|
|
453
|
-
} else {
|
|
454
|
-
array = new Uint8Array(array, byteOffset, length);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
458
|
-
// Return an augmented `Uint8Array` instance, for best performance
|
|
459
|
-
that = array;
|
|
460
|
-
that.__proto__ = Buffer.prototype;
|
|
461
|
-
} else {
|
|
462
|
-
// Fallback: Return an object instance of the Buffer class
|
|
463
|
-
that = fromArrayLike(that, array);
|
|
464
|
-
}
|
|
465
|
-
return that
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function fromObject (that, obj) {
|
|
469
|
-
if (internalIsBuffer(obj)) {
|
|
470
|
-
var len = checked(obj.length) | 0;
|
|
471
|
-
that = createBuffer(that, len);
|
|
472
|
-
|
|
473
|
-
if (that.length === 0) {
|
|
474
|
-
return that
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
obj.copy(that, 0, 0, len);
|
|
478
|
-
return that
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (obj) {
|
|
482
|
-
if ((typeof ArrayBuffer !== 'undefined' &&
|
|
483
|
-
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
|
|
484
|
-
if (typeof obj.length !== 'number' || isnan(obj.length)) {
|
|
485
|
-
return createBuffer(that, 0)
|
|
486
|
-
}
|
|
487
|
-
return fromArrayLike(that, obj)
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (obj.type === 'Buffer' && isArray$1(obj.data)) {
|
|
491
|
-
return fromArrayLike(that, obj.data)
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
function checked (length) {
|
|
499
|
-
// Note: cannot use `length < kMaxLength()` here because that fails when
|
|
500
|
-
// length is NaN (which is otherwise coerced to zero.)
|
|
501
|
-
if (length >= kMaxLength()) {
|
|
502
|
-
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
503
|
-
'size: 0x' + kMaxLength().toString(16) + ' bytes')
|
|
504
|
-
}
|
|
505
|
-
return length | 0
|
|
506
|
-
}
|
|
507
|
-
Buffer.isBuffer = isBuffer;
|
|
508
|
-
function internalIsBuffer (b) {
|
|
509
|
-
return !!(b != null && b._isBuffer)
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
Buffer.compare = function compare (a, b) {
|
|
513
|
-
if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
|
|
514
|
-
throw new TypeError('Arguments must be Buffers')
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (a === b) return 0
|
|
518
|
-
|
|
519
|
-
var x = a.length;
|
|
520
|
-
var y = b.length;
|
|
521
|
-
|
|
522
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
523
|
-
if (a[i] !== b[i]) {
|
|
524
|
-
x = a[i];
|
|
525
|
-
y = b[i];
|
|
526
|
-
break
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if (x < y) return -1
|
|
531
|
-
if (y < x) return 1
|
|
532
|
-
return 0
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
Buffer.isEncoding = function isEncoding (encoding) {
|
|
536
|
-
switch (String(encoding).toLowerCase()) {
|
|
537
|
-
case 'hex':
|
|
538
|
-
case 'utf8':
|
|
539
|
-
case 'utf-8':
|
|
540
|
-
case 'ascii':
|
|
541
|
-
case 'latin1':
|
|
542
|
-
case 'binary':
|
|
543
|
-
case 'base64':
|
|
544
|
-
case 'ucs2':
|
|
545
|
-
case 'ucs-2':
|
|
546
|
-
case 'utf16le':
|
|
547
|
-
case 'utf-16le':
|
|
548
|
-
return true
|
|
549
|
-
default:
|
|
550
|
-
return false
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
Buffer.concat = function concat (list, length) {
|
|
555
|
-
if (!isArray$1(list)) {
|
|
556
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
if (list.length === 0) {
|
|
560
|
-
return Buffer.alloc(0)
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
var i;
|
|
564
|
-
if (length === undefined) {
|
|
565
|
-
length = 0;
|
|
566
|
-
for (i = 0; i < list.length; ++i) {
|
|
567
|
-
length += list[i].length;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
var buffer = Buffer.allocUnsafe(length);
|
|
572
|
-
var pos = 0;
|
|
573
|
-
for (i = 0; i < list.length; ++i) {
|
|
574
|
-
var buf = list[i];
|
|
575
|
-
if (!internalIsBuffer(buf)) {
|
|
576
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
577
|
-
}
|
|
578
|
-
buf.copy(buffer, pos);
|
|
579
|
-
pos += buf.length;
|
|
580
|
-
}
|
|
581
|
-
return buffer
|
|
582
|
-
};
|
|
583
|
-
|
|
584
|
-
function byteLength (string, encoding) {
|
|
585
|
-
if (internalIsBuffer(string)) {
|
|
586
|
-
return string.length
|
|
587
|
-
}
|
|
588
|
-
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
|
589
|
-
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
|
590
|
-
return string.byteLength
|
|
591
|
-
}
|
|
592
|
-
if (typeof string !== 'string') {
|
|
593
|
-
string = '' + string;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
var len = string.length;
|
|
597
|
-
if (len === 0) return 0
|
|
598
|
-
|
|
599
|
-
// Use a for loop to avoid recursion
|
|
600
|
-
var loweredCase = false;
|
|
601
|
-
for (;;) {
|
|
602
|
-
switch (encoding) {
|
|
603
|
-
case 'ascii':
|
|
604
|
-
case 'latin1':
|
|
605
|
-
case 'binary':
|
|
606
|
-
return len
|
|
607
|
-
case 'utf8':
|
|
608
|
-
case 'utf-8':
|
|
609
|
-
case undefined:
|
|
610
|
-
return utf8ToBytes(string).length
|
|
611
|
-
case 'ucs2':
|
|
612
|
-
case 'ucs-2':
|
|
613
|
-
case 'utf16le':
|
|
614
|
-
case 'utf-16le':
|
|
615
|
-
return len * 2
|
|
616
|
-
case 'hex':
|
|
617
|
-
return len >>> 1
|
|
618
|
-
case 'base64':
|
|
619
|
-
return base64ToBytes(string).length
|
|
620
|
-
default:
|
|
621
|
-
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
|
622
|
-
encoding = ('' + encoding).toLowerCase();
|
|
623
|
-
loweredCase = true;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
Buffer.byteLength = byteLength;
|
|
628
|
-
|
|
629
|
-
function slowToString (encoding, start, end) {
|
|
630
|
-
var loweredCase = false;
|
|
631
|
-
|
|
632
|
-
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
633
|
-
// property of a typed array.
|
|
634
|
-
|
|
635
|
-
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
636
|
-
// to their upper/lower bounds if the value passed is out of range.
|
|
637
|
-
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
638
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
639
|
-
if (start === undefined || start < 0) {
|
|
640
|
-
start = 0;
|
|
641
|
-
}
|
|
642
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
|
643
|
-
// coercion fail below.
|
|
644
|
-
if (start > this.length) {
|
|
645
|
-
return ''
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
if (end === undefined || end > this.length) {
|
|
649
|
-
end = this.length;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (end <= 0) {
|
|
653
|
-
return ''
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
|
657
|
-
end >>>= 0;
|
|
658
|
-
start >>>= 0;
|
|
659
|
-
|
|
660
|
-
if (end <= start) {
|
|
661
|
-
return ''
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
if (!encoding) encoding = 'utf8';
|
|
665
|
-
|
|
666
|
-
while (true) {
|
|
667
|
-
switch (encoding) {
|
|
668
|
-
case 'hex':
|
|
669
|
-
return hexSlice(this, start, end)
|
|
670
|
-
|
|
671
|
-
case 'utf8':
|
|
672
|
-
case 'utf-8':
|
|
673
|
-
return utf8Slice(this, start, end)
|
|
674
|
-
|
|
675
|
-
case 'ascii':
|
|
676
|
-
return asciiSlice(this, start, end)
|
|
677
|
-
|
|
678
|
-
case 'latin1':
|
|
679
|
-
case 'binary':
|
|
680
|
-
return latin1Slice(this, start, end)
|
|
681
|
-
|
|
682
|
-
case 'base64':
|
|
683
|
-
return base64Slice(this, start, end)
|
|
684
|
-
|
|
685
|
-
case 'ucs2':
|
|
686
|
-
case 'ucs-2':
|
|
687
|
-
case 'utf16le':
|
|
688
|
-
case 'utf-16le':
|
|
689
|
-
return utf16leSlice(this, start, end)
|
|
690
|
-
|
|
691
|
-
default:
|
|
692
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
693
|
-
encoding = (encoding + '').toLowerCase();
|
|
694
|
-
loweredCase = true;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
|
700
|
-
// Buffer instances.
|
|
701
|
-
Buffer.prototype._isBuffer = true;
|
|
702
|
-
|
|
703
|
-
function swap (b, n, m) {
|
|
704
|
-
var i = b[n];
|
|
705
|
-
b[n] = b[m];
|
|
706
|
-
b[m] = i;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
Buffer.prototype.swap16 = function swap16 () {
|
|
710
|
-
var len = this.length;
|
|
711
|
-
if (len % 2 !== 0) {
|
|
712
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
713
|
-
}
|
|
714
|
-
for (var i = 0; i < len; i += 2) {
|
|
715
|
-
swap(this, i, i + 1);
|
|
716
|
-
}
|
|
717
|
-
return this
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
Buffer.prototype.swap32 = function swap32 () {
|
|
721
|
-
var len = this.length;
|
|
722
|
-
if (len % 4 !== 0) {
|
|
723
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
724
|
-
}
|
|
725
|
-
for (var i = 0; i < len; i += 4) {
|
|
726
|
-
swap(this, i, i + 3);
|
|
727
|
-
swap(this, i + 1, i + 2);
|
|
728
|
-
}
|
|
729
|
-
return this
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
Buffer.prototype.swap64 = function swap64 () {
|
|
733
|
-
var len = this.length;
|
|
734
|
-
if (len % 8 !== 0) {
|
|
735
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
736
|
-
}
|
|
737
|
-
for (var i = 0; i < len; i += 8) {
|
|
738
|
-
swap(this, i, i + 7);
|
|
739
|
-
swap(this, i + 1, i + 6);
|
|
740
|
-
swap(this, i + 2, i + 5);
|
|
741
|
-
swap(this, i + 3, i + 4);
|
|
742
|
-
}
|
|
743
|
-
return this
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
Buffer.prototype.toString = function toString () {
|
|
747
|
-
var length = this.length | 0;
|
|
748
|
-
if (length === 0) return ''
|
|
749
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
750
|
-
return slowToString.apply(this, arguments)
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
Buffer.prototype.equals = function equals (b) {
|
|
754
|
-
if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
755
|
-
if (this === b) return true
|
|
756
|
-
return Buffer.compare(this, b) === 0
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
Buffer.prototype.inspect = function inspect () {
|
|
760
|
-
var str = '';
|
|
761
|
-
var max = INSPECT_MAX_BYTES;
|
|
762
|
-
if (this.length > 0) {
|
|
763
|
-
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
|
|
764
|
-
if (this.length > max) str += ' ... ';
|
|
765
|
-
}
|
|
766
|
-
return '<Buffer ' + str + '>'
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
770
|
-
if (!internalIsBuffer(target)) {
|
|
771
|
-
throw new TypeError('Argument must be a Buffer')
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
if (start === undefined) {
|
|
775
|
-
start = 0;
|
|
776
|
-
}
|
|
777
|
-
if (end === undefined) {
|
|
778
|
-
end = target ? target.length : 0;
|
|
779
|
-
}
|
|
780
|
-
if (thisStart === undefined) {
|
|
781
|
-
thisStart = 0;
|
|
782
|
-
}
|
|
783
|
-
if (thisEnd === undefined) {
|
|
784
|
-
thisEnd = this.length;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
788
|
-
throw new RangeError('out of range index')
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
792
|
-
return 0
|
|
793
|
-
}
|
|
794
|
-
if (thisStart >= thisEnd) {
|
|
795
|
-
return -1
|
|
796
|
-
}
|
|
797
|
-
if (start >= end) {
|
|
798
|
-
return 1
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
start >>>= 0;
|
|
802
|
-
end >>>= 0;
|
|
803
|
-
thisStart >>>= 0;
|
|
804
|
-
thisEnd >>>= 0;
|
|
805
|
-
|
|
806
|
-
if (this === target) return 0
|
|
807
|
-
|
|
808
|
-
var x = thisEnd - thisStart;
|
|
809
|
-
var y = end - start;
|
|
810
|
-
var len = Math.min(x, y);
|
|
811
|
-
|
|
812
|
-
var thisCopy = this.slice(thisStart, thisEnd);
|
|
813
|
-
var targetCopy = target.slice(start, end);
|
|
814
|
-
|
|
815
|
-
for (var i = 0; i < len; ++i) {
|
|
816
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
817
|
-
x = thisCopy[i];
|
|
818
|
-
y = targetCopy[i];
|
|
819
|
-
break
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
if (x < y) return -1
|
|
824
|
-
if (y < x) return 1
|
|
825
|
-
return 0
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
829
|
-
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
830
|
-
//
|
|
831
|
-
// Arguments:
|
|
832
|
-
// - buffer - a Buffer to search
|
|
833
|
-
// - val - a string, Buffer, or number
|
|
834
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
835
|
-
// - encoding - an optional encoding, relevant is val is a string
|
|
836
|
-
// - dir - true for indexOf, false for lastIndexOf
|
|
837
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
838
|
-
// Empty buffer means no match
|
|
839
|
-
if (buffer.length === 0) return -1
|
|
840
|
-
|
|
841
|
-
// Normalize byteOffset
|
|
842
|
-
if (typeof byteOffset === 'string') {
|
|
843
|
-
encoding = byteOffset;
|
|
844
|
-
byteOffset = 0;
|
|
845
|
-
} else if (byteOffset > 0x7fffffff) {
|
|
846
|
-
byteOffset = 0x7fffffff;
|
|
847
|
-
} else if (byteOffset < -0x80000000) {
|
|
848
|
-
byteOffset = -0x80000000;
|
|
849
|
-
}
|
|
850
|
-
byteOffset = +byteOffset; // Coerce to Number.
|
|
851
|
-
if (isNaN(byteOffset)) {
|
|
852
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
853
|
-
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
857
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
858
|
-
if (byteOffset >= buffer.length) {
|
|
859
|
-
if (dir) return -1
|
|
860
|
-
else byteOffset = buffer.length - 1;
|
|
861
|
-
} else if (byteOffset < 0) {
|
|
862
|
-
if (dir) byteOffset = 0;
|
|
863
|
-
else return -1
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
// Normalize val
|
|
867
|
-
if (typeof val === 'string') {
|
|
868
|
-
val = Buffer.from(val, encoding);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
872
|
-
if (internalIsBuffer(val)) {
|
|
873
|
-
// Special case: looking for empty string/buffer always fails
|
|
874
|
-
if (val.length === 0) {
|
|
875
|
-
return -1
|
|
876
|
-
}
|
|
877
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
878
|
-
} else if (typeof val === 'number') {
|
|
879
|
-
val = val & 0xFF; // Search for a byte value [0-255]
|
|
880
|
-
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
|
881
|
-
typeof Uint8Array.prototype.indexOf === 'function') {
|
|
882
|
-
if (dir) {
|
|
883
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
884
|
-
} else {
|
|
885
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
throw new TypeError('val must be string, number or Buffer')
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
895
|
-
var indexSize = 1;
|
|
896
|
-
var arrLength = arr.length;
|
|
897
|
-
var valLength = val.length;
|
|
898
|
-
|
|
899
|
-
if (encoding !== undefined) {
|
|
900
|
-
encoding = String(encoding).toLowerCase();
|
|
901
|
-
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
902
|
-
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
903
|
-
if (arr.length < 2 || val.length < 2) {
|
|
904
|
-
return -1
|
|
905
|
-
}
|
|
906
|
-
indexSize = 2;
|
|
907
|
-
arrLength /= 2;
|
|
908
|
-
valLength /= 2;
|
|
909
|
-
byteOffset /= 2;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
function read (buf, i) {
|
|
914
|
-
if (indexSize === 1) {
|
|
915
|
-
return buf[i]
|
|
916
|
-
} else {
|
|
917
|
-
return buf.readUInt16BE(i * indexSize)
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
var i;
|
|
922
|
-
if (dir) {
|
|
923
|
-
var foundIndex = -1;
|
|
924
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
925
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
926
|
-
if (foundIndex === -1) foundIndex = i;
|
|
927
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
928
|
-
} else {
|
|
929
|
-
if (foundIndex !== -1) i -= i - foundIndex;
|
|
930
|
-
foundIndex = -1;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
} else {
|
|
934
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
935
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
936
|
-
var found = true;
|
|
937
|
-
for (var j = 0; j < valLength; j++) {
|
|
938
|
-
if (read(arr, i + j) !== read(val, j)) {
|
|
939
|
-
found = false;
|
|
940
|
-
break
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
if (found) return i
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
return -1
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
951
|
-
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
955
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
959
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
function hexWrite (buf, string, offset, length) {
|
|
963
|
-
offset = Number(offset) || 0;
|
|
964
|
-
var remaining = buf.length - offset;
|
|
965
|
-
if (!length) {
|
|
966
|
-
length = remaining;
|
|
967
|
-
} else {
|
|
968
|
-
length = Number(length);
|
|
969
|
-
if (length > remaining) {
|
|
970
|
-
length = remaining;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
// must be an even number of digits
|
|
975
|
-
var strLen = string.length;
|
|
976
|
-
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
|
977
|
-
|
|
978
|
-
if (length > strLen / 2) {
|
|
979
|
-
length = strLen / 2;
|
|
980
|
-
}
|
|
981
|
-
for (var i = 0; i < length; ++i) {
|
|
982
|
-
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
983
|
-
if (isNaN(parsed)) return i
|
|
984
|
-
buf[offset + i] = parsed;
|
|
985
|
-
}
|
|
986
|
-
return i
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
function utf8Write (buf, string, offset, length) {
|
|
990
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
function asciiWrite (buf, string, offset, length) {
|
|
994
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
function latin1Write (buf, string, offset, length) {
|
|
998
|
-
return asciiWrite(buf, string, offset, length)
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
function base64Write (buf, string, offset, length) {
|
|
1002
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
function ucs2Write (buf, string, offset, length) {
|
|
1006
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
1010
|
-
// Buffer#write(string)
|
|
1011
|
-
if (offset === undefined) {
|
|
1012
|
-
encoding = 'utf8';
|
|
1013
|
-
length = this.length;
|
|
1014
|
-
offset = 0;
|
|
1015
|
-
// Buffer#write(string, encoding)
|
|
1016
|
-
} else if (length === undefined && typeof offset === 'string') {
|
|
1017
|
-
encoding = offset;
|
|
1018
|
-
length = this.length;
|
|
1019
|
-
offset = 0;
|
|
1020
|
-
// Buffer#write(string, offset[, length][, encoding])
|
|
1021
|
-
} else if (isFinite(offset)) {
|
|
1022
|
-
offset = offset | 0;
|
|
1023
|
-
if (isFinite(length)) {
|
|
1024
|
-
length = length | 0;
|
|
1025
|
-
if (encoding === undefined) encoding = 'utf8';
|
|
1026
|
-
} else {
|
|
1027
|
-
encoding = length;
|
|
1028
|
-
length = undefined;
|
|
1029
|
-
}
|
|
1030
|
-
// legacy write(string, encoding, offset, length) - remove in v0.13
|
|
1031
|
-
} else {
|
|
1032
|
-
throw new Error(
|
|
1033
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1034
|
-
)
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
var remaining = this.length - offset;
|
|
1038
|
-
if (length === undefined || length > remaining) length = remaining;
|
|
1039
|
-
|
|
1040
|
-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1041
|
-
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
if (!encoding) encoding = 'utf8';
|
|
1045
|
-
|
|
1046
|
-
var loweredCase = false;
|
|
1047
|
-
for (;;) {
|
|
1048
|
-
switch (encoding) {
|
|
1049
|
-
case 'hex':
|
|
1050
|
-
return hexWrite(this, string, offset, length)
|
|
1051
|
-
|
|
1052
|
-
case 'utf8':
|
|
1053
|
-
case 'utf-8':
|
|
1054
|
-
return utf8Write(this, string, offset, length)
|
|
1055
|
-
|
|
1056
|
-
case 'ascii':
|
|
1057
|
-
return asciiWrite(this, string, offset, length)
|
|
1058
|
-
|
|
1059
|
-
case 'latin1':
|
|
1060
|
-
case 'binary':
|
|
1061
|
-
return latin1Write(this, string, offset, length)
|
|
1062
|
-
|
|
1063
|
-
case 'base64':
|
|
1064
|
-
// Warning: maxLength not taken into account in base64Write
|
|
1065
|
-
return base64Write(this, string, offset, length)
|
|
1066
|
-
|
|
1067
|
-
case 'ucs2':
|
|
1068
|
-
case 'ucs-2':
|
|
1069
|
-
case 'utf16le':
|
|
1070
|
-
case 'utf-16le':
|
|
1071
|
-
return ucs2Write(this, string, offset, length)
|
|
1072
|
-
|
|
1073
|
-
default:
|
|
1074
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1075
|
-
encoding = ('' + encoding).toLowerCase();
|
|
1076
|
-
loweredCase = true;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
Buffer.prototype.toJSON = function toJSON () {
|
|
1082
|
-
return {
|
|
1083
|
-
type: 'Buffer',
|
|
1084
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
|
|
1088
|
-
function base64Slice (buf, start, end) {
|
|
1089
|
-
if (start === 0 && end === buf.length) {
|
|
1090
|
-
return fromByteArray(buf)
|
|
1091
|
-
} else {
|
|
1092
|
-
return fromByteArray(buf.slice(start, end))
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
function utf8Slice (buf, start, end) {
|
|
1097
|
-
end = Math.min(buf.length, end);
|
|
1098
|
-
var res = [];
|
|
1099
|
-
|
|
1100
|
-
var i = start;
|
|
1101
|
-
while (i < end) {
|
|
1102
|
-
var firstByte = buf[i];
|
|
1103
|
-
var codePoint = null;
|
|
1104
|
-
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
|
1105
|
-
: (firstByte > 0xDF) ? 3
|
|
1106
|
-
: (firstByte > 0xBF) ? 2
|
|
1107
|
-
: 1;
|
|
1108
|
-
|
|
1109
|
-
if (i + bytesPerSequence <= end) {
|
|
1110
|
-
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1111
|
-
|
|
1112
|
-
switch (bytesPerSequence) {
|
|
1113
|
-
case 1:
|
|
1114
|
-
if (firstByte < 0x80) {
|
|
1115
|
-
codePoint = firstByte;
|
|
1116
|
-
}
|
|
1117
|
-
break
|
|
1118
|
-
case 2:
|
|
1119
|
-
secondByte = buf[i + 1];
|
|
1120
|
-
if ((secondByte & 0xC0) === 0x80) {
|
|
1121
|
-
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
1122
|
-
if (tempCodePoint > 0x7F) {
|
|
1123
|
-
codePoint = tempCodePoint;
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
break
|
|
1127
|
-
case 3:
|
|
1128
|
-
secondByte = buf[i + 1];
|
|
1129
|
-
thirdByte = buf[i + 2];
|
|
1130
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1131
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
1132
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1133
|
-
codePoint = tempCodePoint;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
break
|
|
1137
|
-
case 4:
|
|
1138
|
-
secondByte = buf[i + 1];
|
|
1139
|
-
thirdByte = buf[i + 2];
|
|
1140
|
-
fourthByte = buf[i + 3];
|
|
1141
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1142
|
-
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
1143
|
-
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1144
|
-
codePoint = tempCodePoint;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
if (codePoint === null) {
|
|
1151
|
-
// we did not generate a valid codePoint so insert a
|
|
1152
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
|
1153
|
-
codePoint = 0xFFFD;
|
|
1154
|
-
bytesPerSequence = 1;
|
|
1155
|
-
} else if (codePoint > 0xFFFF) {
|
|
1156
|
-
// encode to utf16 (surrogate pair dance)
|
|
1157
|
-
codePoint -= 0x10000;
|
|
1158
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
1159
|
-
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
res.push(codePoint);
|
|
1163
|
-
i += bytesPerSequence;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
return decodeCodePointsArray(res)
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1170
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
|
1171
|
-
// We go 1 magnitude less, for safety
|
|
1172
|
-
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
1173
|
-
|
|
1174
|
-
function decodeCodePointsArray (codePoints) {
|
|
1175
|
-
var len = codePoints.length;
|
|
1176
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1177
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
// Decode in chunks to avoid "call stack size exceeded".
|
|
1181
|
-
var res = '';
|
|
1182
|
-
var i = 0;
|
|
1183
|
-
while (i < len) {
|
|
1184
|
-
res += String.fromCharCode.apply(
|
|
1185
|
-
String,
|
|
1186
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1187
|
-
);
|
|
1188
|
-
}
|
|
1189
|
-
return res
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
function asciiSlice (buf, start, end) {
|
|
1193
|
-
var ret = '';
|
|
1194
|
-
end = Math.min(buf.length, end);
|
|
1195
|
-
|
|
1196
|
-
for (var i = start; i < end; ++i) {
|
|
1197
|
-
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
1198
|
-
}
|
|
1199
|
-
return ret
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
function latin1Slice (buf, start, end) {
|
|
1203
|
-
var ret = '';
|
|
1204
|
-
end = Math.min(buf.length, end);
|
|
1205
|
-
|
|
1206
|
-
for (var i = start; i < end; ++i) {
|
|
1207
|
-
ret += String.fromCharCode(buf[i]);
|
|
1208
|
-
}
|
|
1209
|
-
return ret
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
function hexSlice (buf, start, end) {
|
|
1213
|
-
var len = buf.length;
|
|
1214
|
-
|
|
1215
|
-
if (!start || start < 0) start = 0;
|
|
1216
|
-
if (!end || end < 0 || end > len) end = len;
|
|
1217
|
-
|
|
1218
|
-
var out = '';
|
|
1219
|
-
for (var i = start; i < end; ++i) {
|
|
1220
|
-
out += toHex(buf[i]);
|
|
1221
|
-
}
|
|
1222
|
-
return out
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
function utf16leSlice (buf, start, end) {
|
|
1226
|
-
var bytes = buf.slice(start, end);
|
|
1227
|
-
var res = '';
|
|
1228
|
-
for (var i = 0; i < bytes.length; i += 2) {
|
|
1229
|
-
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1230
|
-
}
|
|
1231
|
-
return res
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
Buffer.prototype.slice = function slice (start, end) {
|
|
1235
|
-
var len = this.length;
|
|
1236
|
-
start = ~~start;
|
|
1237
|
-
end = end === undefined ? len : ~~end;
|
|
1238
|
-
|
|
1239
|
-
if (start < 0) {
|
|
1240
|
-
start += len;
|
|
1241
|
-
if (start < 0) start = 0;
|
|
1242
|
-
} else if (start > len) {
|
|
1243
|
-
start = len;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
if (end < 0) {
|
|
1247
|
-
end += len;
|
|
1248
|
-
if (end < 0) end = 0;
|
|
1249
|
-
} else if (end > len) {
|
|
1250
|
-
end = len;
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
if (end < start) end = start;
|
|
1254
|
-
|
|
1255
|
-
var newBuf;
|
|
1256
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1257
|
-
newBuf = this.subarray(start, end);
|
|
1258
|
-
newBuf.__proto__ = Buffer.prototype;
|
|
1259
|
-
} else {
|
|
1260
|
-
var sliceLen = end - start;
|
|
1261
|
-
newBuf = new Buffer(sliceLen, undefined);
|
|
1262
|
-
for (var i = 0; i < sliceLen; ++i) {
|
|
1263
|
-
newBuf[i] = this[i + start];
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
return newBuf
|
|
1268
|
-
};
|
|
1269
|
-
|
|
1270
|
-
/*
|
|
1271
|
-
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1272
|
-
*/
|
|
1273
|
-
function checkOffset (offset, ext, length) {
|
|
1274
|
-
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1275
|
-
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1279
|
-
offset = offset | 0;
|
|
1280
|
-
byteLength = byteLength | 0;
|
|
1281
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1282
|
-
|
|
1283
|
-
var val = this[offset];
|
|
1284
|
-
var mul = 1;
|
|
1285
|
-
var i = 0;
|
|
1286
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1287
|
-
val += this[offset + i] * mul;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
return val
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1294
|
-
offset = offset | 0;
|
|
1295
|
-
byteLength = byteLength | 0;
|
|
1296
|
-
if (!noAssert) {
|
|
1297
|
-
checkOffset(offset, byteLength, this.length);
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
var val = this[offset + --byteLength];
|
|
1301
|
-
var mul = 1;
|
|
1302
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1303
|
-
val += this[offset + --byteLength] * mul;
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
return val
|
|
1307
|
-
};
|
|
1308
|
-
|
|
1309
|
-
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1310
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1311
|
-
return this[offset]
|
|
1312
|
-
};
|
|
1313
|
-
|
|
1314
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1315
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1316
|
-
return this[offset] | (this[offset + 1] << 8)
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1320
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1321
|
-
return (this[offset] << 8) | this[offset + 1]
|
|
1322
|
-
};
|
|
1323
|
-
|
|
1324
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1325
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1326
|
-
|
|
1327
|
-
return ((this[offset]) |
|
|
1328
|
-
(this[offset + 1] << 8) |
|
|
1329
|
-
(this[offset + 2] << 16)) +
|
|
1330
|
-
(this[offset + 3] * 0x1000000)
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
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
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1380
|
-
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1381
|
-
return ((0xff - this[offset] + 1) * -1)
|
|
1382
|
-
};
|
|
1383
|
-
|
|
1384
|
-
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1385
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1386
|
-
var val = this[offset] | (this[offset + 1] << 8);
|
|
1387
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1388
|
-
};
|
|
1389
|
-
|
|
1390
|
-
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1391
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1392
|
-
var val = this[offset + 1] | (this[offset] << 8);
|
|
1393
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1394
|
-
};
|
|
1395
|
-
|
|
1396
|
-
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1397
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1398
|
-
|
|
1399
|
-
return (this[offset]) |
|
|
1400
|
-
(this[offset + 1] << 8) |
|
|
1401
|
-
(this[offset + 2] << 16) |
|
|
1402
|
-
(this[offset + 3] << 24)
|
|
1403
|
-
};
|
|
1404
|
-
|
|
1405
|
-
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1406
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1407
|
-
|
|
1408
|
-
return (this[offset] << 24) |
|
|
1409
|
-
(this[offset + 1] << 16) |
|
|
1410
|
-
(this[offset + 2] << 8) |
|
|
1411
|
-
(this[offset + 3])
|
|
1412
|
-
};
|
|
1413
|
-
|
|
1414
|
-
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1415
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1416
|
-
return read(this, offset, true, 23, 4)
|
|
1417
|
-
};
|
|
1418
|
-
|
|
1419
|
-
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1420
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1421
|
-
return read(this, offset, false, 23, 4)
|
|
1422
|
-
};
|
|
1423
|
-
|
|
1424
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1425
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1426
|
-
return read(this, offset, true, 52, 8)
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1430
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1431
|
-
return read(this, offset, false, 52, 8)
|
|
1432
|
-
};
|
|
1433
|
-
|
|
1434
|
-
function checkInt (buf, value, offset, ext, max, min) {
|
|
1435
|
-
if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1436
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1437
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1441
|
-
value = +value;
|
|
1442
|
-
offset = offset | 0;
|
|
1443
|
-
byteLength = byteLength | 0;
|
|
1444
|
-
if (!noAssert) {
|
|
1445
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1446
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
var mul = 1;
|
|
1450
|
-
var i = 0;
|
|
1451
|
-
this[offset] = value & 0xFF;
|
|
1452
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1453
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
return offset + byteLength
|
|
1457
|
-
};
|
|
1458
|
-
|
|
1459
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1460
|
-
value = +value;
|
|
1461
|
-
offset = offset | 0;
|
|
1462
|
-
byteLength = byteLength | 0;
|
|
1463
|
-
if (!noAssert) {
|
|
1464
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1465
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
var i = byteLength - 1;
|
|
1469
|
-
var mul = 1;
|
|
1470
|
-
this[offset + i] = value & 0xFF;
|
|
1471
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
1472
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
return offset + byteLength
|
|
1476
|
-
};
|
|
1477
|
-
|
|
1478
|
-
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1479
|
-
value = +value;
|
|
1480
|
-
offset = offset | 0;
|
|
1481
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
1482
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1483
|
-
this[offset] = (value & 0xff);
|
|
1484
|
-
return offset + 1
|
|
1485
|
-
};
|
|
1486
|
-
|
|
1487
|
-
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
|
1488
|
-
if (value < 0) value = 0xffff + value + 1;
|
|
1489
|
-
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
|
1490
|
-
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
|
1491
|
-
(littleEndian ? i : 1 - i) * 8;
|
|
1492
|
-
}
|
|
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
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1500
|
-
this[offset] = (value & 0xff);
|
|
1501
|
-
this[offset + 1] = (value >>> 8);
|
|
1502
|
-
} else {
|
|
1503
|
-
objectWriteUInt16(this, value, offset, true);
|
|
1504
|
-
}
|
|
1505
|
-
return offset + 2
|
|
1506
|
-
};
|
|
1507
|
-
|
|
1508
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1509
|
-
value = +value;
|
|
1510
|
-
offset = offset | 0;
|
|
1511
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1512
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1513
|
-
this[offset] = (value >>> 8);
|
|
1514
|
-
this[offset + 1] = (value & 0xff);
|
|
1515
|
-
} else {
|
|
1516
|
-
objectWriteUInt16(this, value, offset, false);
|
|
1517
|
-
}
|
|
1518
|
-
return offset + 2
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
|
-
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
|
1522
|
-
if (value < 0) value = 0xffffffff + value + 1;
|
|
1523
|
-
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
|
1524
|
-
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1529
|
-
value = +value;
|
|
1530
|
-
offset = offset | 0;
|
|
1531
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1532
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1533
|
-
this[offset + 3] = (value >>> 24);
|
|
1534
|
-
this[offset + 2] = (value >>> 16);
|
|
1535
|
-
this[offset + 1] = (value >>> 8);
|
|
1536
|
-
this[offset] = (value & 0xff);
|
|
1537
|
-
} else {
|
|
1538
|
-
objectWriteUInt32(this, value, offset, true);
|
|
1539
|
-
}
|
|
1540
|
-
return offset + 4
|
|
1541
|
-
};
|
|
1542
|
-
|
|
1543
|
-
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1544
|
-
value = +value;
|
|
1545
|
-
offset = offset | 0;
|
|
1546
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1547
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1548
|
-
this[offset] = (value >>> 24);
|
|
1549
|
-
this[offset + 1] = (value >>> 16);
|
|
1550
|
-
this[offset + 2] = (value >>> 8);
|
|
1551
|
-
this[offset + 3] = (value & 0xff);
|
|
1552
|
-
} else {
|
|
1553
|
-
objectWriteUInt32(this, value, offset, false);
|
|
1554
|
-
}
|
|
1555
|
-
return offset + 4
|
|
1556
|
-
};
|
|
1557
|
-
|
|
1558
|
-
Buffer.prototype.writeIntLE = function writeIntLE (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 = 0;
|
|
1568
|
-
var mul = 1;
|
|
1569
|
-
var sub = 0;
|
|
1570
|
-
this[offset] = value & 0xFF;
|
|
1571
|
-
while (++i < byteLength && (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.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1582
|
-
value = +value;
|
|
1583
|
-
offset = offset | 0;
|
|
1584
|
-
if (!noAssert) {
|
|
1585
|
-
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1586
|
-
|
|
1587
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
var i = byteLength - 1;
|
|
1591
|
-
var mul = 1;
|
|
1592
|
-
var sub = 0;
|
|
1593
|
-
this[offset + i] = value & 0xFF;
|
|
1594
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
1595
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1596
|
-
sub = 1;
|
|
1597
|
-
}
|
|
1598
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
return offset + byteLength
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
|
-
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1605
|
-
value = +value;
|
|
1606
|
-
offset = offset | 0;
|
|
1607
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
1608
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1609
|
-
if (value < 0) value = 0xff + value + 1;
|
|
1610
|
-
this[offset] = (value & 0xff);
|
|
1611
|
-
return offset + 1
|
|
1612
|
-
};
|
|
1613
|
-
|
|
1614
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1615
|
-
value = +value;
|
|
1616
|
-
offset = offset | 0;
|
|
1617
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1618
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1619
|
-
this[offset] = (value & 0xff);
|
|
1620
|
-
this[offset + 1] = (value >>> 8);
|
|
1621
|
-
} else {
|
|
1622
|
-
objectWriteUInt16(this, value, offset, true);
|
|
1623
|
-
}
|
|
1624
|
-
return offset + 2
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1628
|
-
value = +value;
|
|
1629
|
-
offset = offset | 0;
|
|
1630
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1631
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1632
|
-
this[offset] = (value >>> 8);
|
|
1633
|
-
this[offset + 1] = (value & 0xff);
|
|
1634
|
-
} else {
|
|
1635
|
-
objectWriteUInt16(this, value, offset, false);
|
|
1636
|
-
}
|
|
1637
|
-
return offset + 2
|
|
1638
|
-
};
|
|
1639
|
-
|
|
1640
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1641
|
-
value = +value;
|
|
1642
|
-
offset = offset | 0;
|
|
1643
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1644
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1645
|
-
this[offset] = (value & 0xff);
|
|
1646
|
-
this[offset + 1] = (value >>> 8);
|
|
1647
|
-
this[offset + 2] = (value >>> 16);
|
|
1648
|
-
this[offset + 3] = (value >>> 24);
|
|
1649
|
-
} else {
|
|
1650
|
-
objectWriteUInt32(this, value, offset, true);
|
|
1651
|
-
}
|
|
1652
|
-
return offset + 4
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1656
|
-
value = +value;
|
|
1657
|
-
offset = offset | 0;
|
|
1658
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1659
|
-
if (value < 0) value = 0xffffffff + value + 1;
|
|
1660
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1661
|
-
this[offset] = (value >>> 24);
|
|
1662
|
-
this[offset + 1] = (value >>> 16);
|
|
1663
|
-
this[offset + 2] = (value >>> 8);
|
|
1664
|
-
this[offset + 3] = (value & 0xff);
|
|
1665
|
-
} else {
|
|
1666
|
-
objectWriteUInt32(this, value, offset, false);
|
|
1667
|
-
}
|
|
1668
|
-
return offset + 4
|
|
1669
|
-
};
|
|
1670
|
-
|
|
1671
|
-
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1672
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1673
|
-
if (offset < 0) throw new RangeError('Index out of range')
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1677
|
-
if (!noAssert) {
|
|
1678
|
-
checkIEEE754(buf, value, offset, 4);
|
|
1679
|
-
}
|
|
1680
|
-
write(buf, value, offset, littleEndian, 23, 4);
|
|
1681
|
-
return offset + 4
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1685
|
-
return writeFloat(this, value, offset, true, noAssert)
|
|
1686
|
-
};
|
|
1687
|
-
|
|
1688
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1689
|
-
return writeFloat(this, value, offset, false, noAssert)
|
|
1690
|
-
};
|
|
1691
|
-
|
|
1692
|
-
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1693
|
-
if (!noAssert) {
|
|
1694
|
-
checkIEEE754(buf, value, offset, 8);
|
|
1695
|
-
}
|
|
1696
|
-
write(buf, value, offset, littleEndian, 52, 8);
|
|
1697
|
-
return offset + 8
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1701
|
-
return writeDouble(this, value, offset, true, noAssert)
|
|
1702
|
-
};
|
|
1703
|
-
|
|
1704
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1705
|
-
return writeDouble(this, value, offset, false, noAssert)
|
|
1706
|
-
};
|
|
1707
|
-
|
|
1708
|
-
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1709
|
-
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1710
|
-
if (!start) start = 0;
|
|
1711
|
-
if (!end && end !== 0) end = this.length;
|
|
1712
|
-
if (targetStart >= target.length) targetStart = target.length;
|
|
1713
|
-
if (!targetStart) targetStart = 0;
|
|
1714
|
-
if (end > 0 && end < start) end = start;
|
|
1715
|
-
|
|
1716
|
-
// Copy 0 bytes; we're done
|
|
1717
|
-
if (end === start) return 0
|
|
1718
|
-
if (target.length === 0 || this.length === 0) return 0
|
|
1719
|
-
|
|
1720
|
-
// Fatal error conditions
|
|
1721
|
-
if (targetStart < 0) {
|
|
1722
|
-
throw new RangeError('targetStart out of bounds')
|
|
1723
|
-
}
|
|
1724
|
-
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
|
1725
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1726
|
-
|
|
1727
|
-
// Are we oob?
|
|
1728
|
-
if (end > this.length) end = this.length;
|
|
1729
|
-
if (target.length - targetStart < end - start) {
|
|
1730
|
-
end = target.length - targetStart + start;
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
var len = end - start;
|
|
1734
|
-
var i;
|
|
1735
|
-
|
|
1736
|
-
if (this === target && start < targetStart && targetStart < end) {
|
|
1737
|
-
// descending copy from end
|
|
1738
|
-
for (i = len - 1; i >= 0; --i) {
|
|
1739
|
-
target[i + targetStart] = this[i + start];
|
|
1740
|
-
}
|
|
1741
|
-
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1742
|
-
// ascending copy from start
|
|
1743
|
-
for (i = 0; i < len; ++i) {
|
|
1744
|
-
target[i + targetStart] = this[i + start];
|
|
1745
|
-
}
|
|
1746
|
-
} else {
|
|
1747
|
-
Uint8Array.prototype.set.call(
|
|
1748
|
-
target,
|
|
1749
|
-
this.subarray(start, start + len),
|
|
1750
|
-
targetStart
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
return len
|
|
1755
|
-
};
|
|
1756
|
-
|
|
1757
|
-
// Usage:
|
|
1758
|
-
// buffer.fill(number[, offset[, end]])
|
|
1759
|
-
// buffer.fill(buffer[, offset[, end]])
|
|
1760
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
|
1761
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
1762
|
-
// Handle string cases:
|
|
1763
|
-
if (typeof val === 'string') {
|
|
1764
|
-
if (typeof start === 'string') {
|
|
1765
|
-
encoding = start;
|
|
1766
|
-
start = 0;
|
|
1767
|
-
end = this.length;
|
|
1768
|
-
} else if (typeof end === 'string') {
|
|
1769
|
-
encoding = end;
|
|
1770
|
-
end = this.length;
|
|
1771
|
-
}
|
|
1772
|
-
if (val.length === 1) {
|
|
1773
|
-
var code = val.charCodeAt(0);
|
|
1774
|
-
if (code < 256) {
|
|
1775
|
-
val = code;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
1779
|
-
throw new TypeError('encoding must be a string')
|
|
1780
|
-
}
|
|
1781
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
1782
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1783
|
-
}
|
|
1784
|
-
} else if (typeof val === 'number') {
|
|
1785
|
-
val = val & 255;
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
// Invalid ranges are not set to a default, so can range check early.
|
|
1789
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
1790
|
-
throw new RangeError('Out of range index')
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
if (end <= start) {
|
|
1794
|
-
return this
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
start = start >>> 0;
|
|
1798
|
-
end = end === undefined ? this.length : end >>> 0;
|
|
1799
|
-
|
|
1800
|
-
if (!val) val = 0;
|
|
1801
|
-
|
|
1802
|
-
var i;
|
|
1803
|
-
if (typeof val === 'number') {
|
|
1804
|
-
for (i = start; i < end; ++i) {
|
|
1805
|
-
this[i] = val;
|
|
1806
|
-
}
|
|
1807
|
-
} else {
|
|
1808
|
-
var bytes = internalIsBuffer(val)
|
|
1809
|
-
? val
|
|
1810
|
-
: utf8ToBytes(new Buffer(val, encoding).toString());
|
|
1811
|
-
var len = bytes.length;
|
|
1812
|
-
for (i = 0; i < end - start; ++i) {
|
|
1813
|
-
this[i + start] = bytes[i % len];
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
return this
|
|
1818
|
-
};
|
|
1819
|
-
|
|
1820
|
-
// HELPER FUNCTIONS
|
|
1821
|
-
// ================
|
|
1822
|
-
|
|
1823
|
-
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
|
|
1824
|
-
|
|
1825
|
-
function base64clean (str) {
|
|
1826
|
-
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
1827
|
-
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
|
|
1828
|
-
// Node converts strings with length < 2 to ''
|
|
1829
|
-
if (str.length < 2) return ''
|
|
1830
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
1831
|
-
while (str.length % 4 !== 0) {
|
|
1832
|
-
str = str + '=';
|
|
1833
|
-
}
|
|
1834
|
-
return str
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
function stringtrim (str) {
|
|
1838
|
-
if (str.trim) return str.trim()
|
|
1839
|
-
return str.replace(/^\s+|\s+$/g, '')
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
function toHex (n) {
|
|
1843
|
-
if (n < 16) return '0' + n.toString(16)
|
|
1844
|
-
return n.toString(16)
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
function utf8ToBytes (string, units) {
|
|
1848
|
-
units = units || Infinity;
|
|
1849
|
-
var codePoint;
|
|
1850
|
-
var length = string.length;
|
|
1851
|
-
var leadSurrogate = null;
|
|
1852
|
-
var bytes = [];
|
|
1853
|
-
|
|
1854
|
-
for (var i = 0; i < length; ++i) {
|
|
1855
|
-
codePoint = string.charCodeAt(i);
|
|
1856
|
-
|
|
1857
|
-
// is surrogate component
|
|
1858
|
-
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
1859
|
-
// last char was a lead
|
|
1860
|
-
if (!leadSurrogate) {
|
|
1861
|
-
// no lead yet
|
|
1862
|
-
if (codePoint > 0xDBFF) {
|
|
1863
|
-
// unexpected trail
|
|
1864
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1865
|
-
continue
|
|
1866
|
-
} else if (i + 1 === length) {
|
|
1867
|
-
// unpaired lead
|
|
1868
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1869
|
-
continue
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
// valid lead
|
|
1873
|
-
leadSurrogate = codePoint;
|
|
1874
|
-
|
|
1875
|
-
continue
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
// 2 leads in a row
|
|
1879
|
-
if (codePoint < 0xDC00) {
|
|
1880
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1881
|
-
leadSurrogate = codePoint;
|
|
1882
|
-
continue
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
// valid surrogate pair
|
|
1886
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
1887
|
-
} else if (leadSurrogate) {
|
|
1888
|
-
// valid bmp char, but last char was a lead
|
|
1889
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
leadSurrogate = null;
|
|
1893
|
-
|
|
1894
|
-
// encode utf8
|
|
1895
|
-
if (codePoint < 0x80) {
|
|
1896
|
-
if ((units -= 1) < 0) break
|
|
1897
|
-
bytes.push(codePoint);
|
|
1898
|
-
} else if (codePoint < 0x800) {
|
|
1899
|
-
if ((units -= 2) < 0) break
|
|
1900
|
-
bytes.push(
|
|
1901
|
-
codePoint >> 0x6 | 0xC0,
|
|
1902
|
-
codePoint & 0x3F | 0x80
|
|
1903
|
-
);
|
|
1904
|
-
} else if (codePoint < 0x10000) {
|
|
1905
|
-
if ((units -= 3) < 0) break
|
|
1906
|
-
bytes.push(
|
|
1907
|
-
codePoint >> 0xC | 0xE0,
|
|
1908
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1909
|
-
codePoint & 0x3F | 0x80
|
|
1910
|
-
);
|
|
1911
|
-
} else if (codePoint < 0x110000) {
|
|
1912
|
-
if ((units -= 4) < 0) break
|
|
1913
|
-
bytes.push(
|
|
1914
|
-
codePoint >> 0x12 | 0xF0,
|
|
1915
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
|
1916
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1917
|
-
codePoint & 0x3F | 0x80
|
|
1918
|
-
);
|
|
1919
|
-
} else {
|
|
1920
|
-
throw new Error('Invalid code point')
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
return bytes
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
function asciiToBytes (str) {
|
|
1928
|
-
var byteArray = [];
|
|
1929
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1930
|
-
// Node's code seems to be doing this and not & 0x7F..
|
|
1931
|
-
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
1932
|
-
}
|
|
1933
|
-
return byteArray
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
function utf16leToBytes (str, units) {
|
|
1937
|
-
var c, hi, lo;
|
|
1938
|
-
var byteArray = [];
|
|
1939
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1940
|
-
if ((units -= 2) < 0) break
|
|
1941
|
-
|
|
1942
|
-
c = str.charCodeAt(i);
|
|
1943
|
-
hi = c >> 8;
|
|
1944
|
-
lo = c % 256;
|
|
1945
|
-
byteArray.push(lo);
|
|
1946
|
-
byteArray.push(hi);
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
return byteArray
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
function base64ToBytes (str) {
|
|
1954
|
-
return toByteArray(base64clean(str))
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
function blitBuffer (src, dst, offset, length) {
|
|
1958
|
-
for (var i = 0; i < length; ++i) {
|
|
1959
|
-
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
1960
|
-
dst[i + offset] = src[i];
|
|
1961
|
-
}
|
|
1962
|
-
return i
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
function isnan (val) {
|
|
1966
|
-
return val !== val // eslint-disable-line no-self-compare
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
// the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
|
|
1971
|
-
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
|
1972
|
-
// Object.prototype.constructor. Remove this eventually
|
|
1973
|
-
function isBuffer(obj) {
|
|
1974
|
-
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
function isFastBuffer (obj) {
|
|
1978
|
-
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
// For Node v0.10 support. Remove this eventually.
|
|
1982
|
-
function isSlowBuffer (obj) {
|
|
1983
|
-
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
var inherits;
|
|
1987
|
-
if (typeof Object.create === 'function'){
|
|
1988
|
-
inherits = function inherits(ctor, superCtor) {
|
|
1989
|
-
// implementation from standard node.js 'util' module
|
|
1990
|
-
ctor.super_ = superCtor;
|
|
1991
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
1992
|
-
constructor: {
|
|
1993
|
-
value: ctor,
|
|
1994
|
-
enumerable: false,
|
|
1995
|
-
writable: true,
|
|
1996
|
-
configurable: true
|
|
1997
|
-
}
|
|
1998
|
-
});
|
|
1999
|
-
};
|
|
2000
|
-
} else {
|
|
2001
|
-
inherits = function inherits(ctor, superCtor) {
|
|
2002
|
-
ctor.super_ = superCtor;
|
|
2003
|
-
var TempCtor = function () {};
|
|
2004
|
-
TempCtor.prototype = superCtor.prototype;
|
|
2005
|
-
ctor.prototype = new TempCtor();
|
|
2006
|
-
ctor.prototype.constructor = ctor;
|
|
2007
|
-
};
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
/**
|
|
2011
|
-
* Echos the value of a value. Trys to print the value out
|
|
2012
|
-
* in the best way possible given the different types.
|
|
2013
|
-
*
|
|
2014
|
-
* @param {Object} obj The object to print out.
|
|
2015
|
-
* @param {Object} opts Optional options object that alters the output.
|
|
2016
|
-
*/
|
|
2017
|
-
/* legacy: obj, showHidden, depth, colors*/
|
|
2018
|
-
function inspect$1(obj, opts) {
|
|
2019
|
-
// default options
|
|
2020
|
-
var ctx = {
|
|
2021
|
-
seen: [],
|
|
2022
|
-
stylize: stylizeNoColor
|
|
2023
|
-
};
|
|
2024
|
-
// legacy...
|
|
2025
|
-
if (arguments.length >= 3) ctx.depth = arguments[2];
|
|
2026
|
-
if (arguments.length >= 4) ctx.colors = arguments[3];
|
|
2027
|
-
if (isBoolean(opts)) {
|
|
2028
|
-
// legacy...
|
|
2029
|
-
ctx.showHidden = opts;
|
|
2030
|
-
} else if (opts) {
|
|
2031
|
-
// got an "options" object
|
|
2032
|
-
_extend(ctx, opts);
|
|
2033
|
-
}
|
|
2034
|
-
// set default options
|
|
2035
|
-
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
|
2036
|
-
if (isUndefined(ctx.depth)) ctx.depth = 2;
|
|
2037
|
-
if (isUndefined(ctx.colors)) ctx.colors = false;
|
|
2038
|
-
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
|
2039
|
-
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
|
2040
|
-
return formatValue(ctx, obj, ctx.depth);
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
2044
|
-
inspect$1.colors = {
|
|
2045
|
-
'bold' : [1, 22],
|
|
2046
|
-
'italic' : [3, 23],
|
|
2047
|
-
'underline' : [4, 24],
|
|
2048
|
-
'inverse' : [7, 27],
|
|
2049
|
-
'white' : [37, 39],
|
|
2050
|
-
'grey' : [90, 39],
|
|
2051
|
-
'black' : [30, 39],
|
|
2052
|
-
'blue' : [34, 39],
|
|
2053
|
-
'cyan' : [36, 39],
|
|
2054
|
-
'green' : [32, 39],
|
|
2055
|
-
'magenta' : [35, 39],
|
|
2056
|
-
'red' : [31, 39],
|
|
2057
|
-
'yellow' : [33, 39]
|
|
2058
|
-
};
|
|
2059
|
-
|
|
2060
|
-
// Don't use 'blue' not visible on cmd.exe
|
|
2061
|
-
inspect$1.styles = {
|
|
2062
|
-
'special': 'cyan',
|
|
2063
|
-
'number': 'yellow',
|
|
2064
|
-
'boolean': 'yellow',
|
|
2065
|
-
'undefined': 'grey',
|
|
2066
|
-
'null': 'bold',
|
|
2067
|
-
'string': 'green',
|
|
2068
|
-
'date': 'magenta',
|
|
2069
|
-
// "name": intentionally not styling
|
|
2070
|
-
'regexp': 'red'
|
|
2071
|
-
};
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
function stylizeWithColor(str, styleType) {
|
|
2075
|
-
var style = inspect$1.styles[styleType];
|
|
2076
|
-
|
|
2077
|
-
if (style) {
|
|
2078
|
-
return '\u001b[' + inspect$1.colors[style][0] + 'm' + str +
|
|
2079
|
-
'\u001b[' + inspect$1.colors[style][1] + 'm';
|
|
2080
|
-
} else {
|
|
2081
|
-
return str;
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
function stylizeNoColor(str, styleType) {
|
|
2087
|
-
return str;
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
function arrayToHash(array) {
|
|
2092
|
-
var hash = {};
|
|
2093
|
-
|
|
2094
|
-
array.forEach(function(val, idx) {
|
|
2095
|
-
hash[val] = true;
|
|
2096
|
-
});
|
|
2097
|
-
|
|
2098
|
-
return hash;
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
function formatValue(ctx, value, recurseTimes) {
|
|
2103
|
-
// Provide a hook for user-specified inspect functions.
|
|
2104
|
-
// Check that value is an object with an inspect function on it
|
|
2105
|
-
if (ctx.customInspect &&
|
|
2106
|
-
value &&
|
|
2107
|
-
isFunction(value.inspect) &&
|
|
2108
|
-
// Filter out the util module, it's inspect function is special
|
|
2109
|
-
value.inspect !== inspect$1 &&
|
|
2110
|
-
// Also filter out any prototype objects using the circular check.
|
|
2111
|
-
!(value.constructor && value.constructor.prototype === value)) {
|
|
2112
|
-
var ret = value.inspect(recurseTimes, ctx);
|
|
2113
|
-
if (!isString(ret)) {
|
|
2114
|
-
ret = formatValue(ctx, ret, recurseTimes);
|
|
2115
|
-
}
|
|
2116
|
-
return ret;
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
// Primitive types cannot have properties
|
|
2120
|
-
var primitive = formatPrimitive(ctx, value);
|
|
2121
|
-
if (primitive) {
|
|
2122
|
-
return primitive;
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
// Look up the keys of the object.
|
|
2126
|
-
var keys = Object.keys(value);
|
|
2127
|
-
var visibleKeys = arrayToHash(keys);
|
|
2128
|
-
|
|
2129
|
-
if (ctx.showHidden) {
|
|
2130
|
-
keys = Object.getOwnPropertyNames(value);
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
// IE doesn't make error fields non-enumerable
|
|
2134
|
-
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
|
|
2135
|
-
if (isError(value)
|
|
2136
|
-
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
|
2137
|
-
return formatError(value);
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
// Some type of object without properties can be shortcutted.
|
|
2141
|
-
if (keys.length === 0) {
|
|
2142
|
-
if (isFunction(value)) {
|
|
2143
|
-
var name = value.name ? ': ' + value.name : '';
|
|
2144
|
-
return ctx.stylize('[Function' + name + ']', 'special');
|
|
2145
|
-
}
|
|
2146
|
-
if (isRegExp(value)) {
|
|
2147
|
-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
2148
|
-
}
|
|
2149
|
-
if (isDate(value)) {
|
|
2150
|
-
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|
2151
|
-
}
|
|
2152
|
-
if (isError(value)) {
|
|
2153
|
-
return formatError(value);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
var base = '', array = false, braces = ['{', '}'];
|
|
2158
|
-
|
|
2159
|
-
// Make Array say that they are Array
|
|
2160
|
-
if (isArray(value)) {
|
|
2161
|
-
array = true;
|
|
2162
|
-
braces = ['[', ']'];
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
// Make functions say that they are functions
|
|
2166
|
-
if (isFunction(value)) {
|
|
2167
|
-
var n = value.name ? ': ' + value.name : '';
|
|
2168
|
-
base = ' [Function' + n + ']';
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
// Make RegExps say that they are RegExps
|
|
2172
|
-
if (isRegExp(value)) {
|
|
2173
|
-
base = ' ' + RegExp.prototype.toString.call(value);
|
|
2174
|
-
}
|
|
2175
|
-
|
|
2176
|
-
// Make dates with properties first say the date
|
|
2177
|
-
if (isDate(value)) {
|
|
2178
|
-
base = ' ' + Date.prototype.toUTCString.call(value);
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
// Make error with message first say the error
|
|
2182
|
-
if (isError(value)) {
|
|
2183
|
-
base = ' ' + formatError(value);
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
if (keys.length === 0 && (!array || value.length == 0)) {
|
|
2187
|
-
return braces[0] + base + braces[1];
|
|
2188
|
-
}
|
|
2189
|
-
|
|
2190
|
-
if (recurseTimes < 0) {
|
|
2191
|
-
if (isRegExp(value)) {
|
|
2192
|
-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
2193
|
-
} else {
|
|
2194
|
-
return ctx.stylize('[Object]', 'special');
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
ctx.seen.push(value);
|
|
2199
|
-
|
|
2200
|
-
var output;
|
|
2201
|
-
if (array) {
|
|
2202
|
-
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|
2203
|
-
} else {
|
|
2204
|
-
output = keys.map(function(key) {
|
|
2205
|
-
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
|
|
2209
|
-
ctx.seen.pop();
|
|
2210
|
-
|
|
2211
|
-
return reduceToSingleString(output, base, braces);
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
function formatPrimitive(ctx, value) {
|
|
2216
|
-
if (isUndefined(value))
|
|
2217
|
-
return ctx.stylize('undefined', 'undefined');
|
|
2218
|
-
if (isString(value)) {
|
|
2219
|
-
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
2220
|
-
.replace(/'/g, "\\'")
|
|
2221
|
-
.replace(/\\"/g, '"') + '\'';
|
|
2222
|
-
return ctx.stylize(simple, 'string');
|
|
2223
|
-
}
|
|
2224
|
-
if (isNumber(value))
|
|
2225
|
-
return ctx.stylize('' + value, 'number');
|
|
2226
|
-
if (isBoolean(value))
|
|
2227
|
-
return ctx.stylize('' + value, 'boolean');
|
|
2228
|
-
// For some reason typeof null is "object", so special case here.
|
|
2229
|
-
if (isNull(value))
|
|
2230
|
-
return ctx.stylize('null', 'null');
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
function formatError(value) {
|
|
2235
|
-
return '[' + Error.prototype.toString.call(value) + ']';
|
|
2236
|
-
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
2240
|
-
var output = [];
|
|
2241
|
-
for (var i = 0, l = value.length; i < l; ++i) {
|
|
2242
|
-
if (hasOwnProperty(value, String(i))) {
|
|
2243
|
-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
2244
|
-
String(i), true));
|
|
2245
|
-
} else {
|
|
2246
|
-
output.push('');
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
keys.forEach(function(key) {
|
|
2250
|
-
if (!key.match(/^\d+$/)) {
|
|
2251
|
-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
2252
|
-
key, true));
|
|
2253
|
-
}
|
|
2254
|
-
});
|
|
2255
|
-
return output;
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
2260
|
-
var name, str, desc;
|
|
2261
|
-
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|
2262
|
-
if (desc.get) {
|
|
2263
|
-
if (desc.set) {
|
|
2264
|
-
str = ctx.stylize('[Getter/Setter]', 'special');
|
|
2265
|
-
} else {
|
|
2266
|
-
str = ctx.stylize('[Getter]', 'special');
|
|
2267
|
-
}
|
|
2268
|
-
} else {
|
|
2269
|
-
if (desc.set) {
|
|
2270
|
-
str = ctx.stylize('[Setter]', 'special');
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
if (!hasOwnProperty(visibleKeys, key)) {
|
|
2274
|
-
name = '[' + key + ']';
|
|
2275
|
-
}
|
|
2276
|
-
if (!str) {
|
|
2277
|
-
if (ctx.seen.indexOf(desc.value) < 0) {
|
|
2278
|
-
if (isNull(recurseTimes)) {
|
|
2279
|
-
str = formatValue(ctx, desc.value, null);
|
|
2280
|
-
} else {
|
|
2281
|
-
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|
2282
|
-
}
|
|
2283
|
-
if (str.indexOf('\n') > -1) {
|
|
2284
|
-
if (array) {
|
|
2285
|
-
str = str.split('\n').map(function(line) {
|
|
2286
|
-
return ' ' + line;
|
|
2287
|
-
}).join('\n').substr(2);
|
|
2288
|
-
} else {
|
|
2289
|
-
str = '\n' + str.split('\n').map(function(line) {
|
|
2290
|
-
return ' ' + line;
|
|
2291
|
-
}).join('\n');
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
} else {
|
|
2295
|
-
str = ctx.stylize('[Circular]', 'special');
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
if (isUndefined(name)) {
|
|
2299
|
-
if (array && key.match(/^\d+$/)) {
|
|
2300
|
-
return str;
|
|
2301
|
-
}
|
|
2302
|
-
name = JSON.stringify('' + key);
|
|
2303
|
-
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
2304
|
-
name = name.substr(1, name.length - 2);
|
|
2305
|
-
name = ctx.stylize(name, 'name');
|
|
2306
|
-
} else {
|
|
2307
|
-
name = name.replace(/'/g, "\\'")
|
|
2308
|
-
.replace(/\\"/g, '"')
|
|
2309
|
-
.replace(/(^"|"$)/g, "'");
|
|
2310
|
-
name = ctx.stylize(name, 'string');
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
return name + ': ' + str;
|
|
2315
|
-
}
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
function reduceToSingleString(output, base, braces) {
|
|
2319
|
-
var length = output.reduce(function(prev, cur) {
|
|
2320
|
-
if (cur.indexOf('\n') >= 0) ;
|
|
2321
|
-
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
|
2322
|
-
}, 0);
|
|
2323
|
-
|
|
2324
|
-
if (length > 60) {
|
|
2325
|
-
return braces[0] +
|
|
2326
|
-
(base === '' ? '' : base + '\n ') +
|
|
2327
|
-
' ' +
|
|
2328
|
-
output.join(',\n ') +
|
|
2329
|
-
' ' +
|
|
2330
|
-
braces[1];
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|
2338
|
-
// because it is fragile and can be easily faked with `Object.create()`.
|
|
2339
|
-
function isArray(ar) {
|
|
2340
|
-
return Array.isArray(ar);
|
|
2341
|
-
}
|
|
2342
|
-
|
|
2343
|
-
function isBoolean(arg) {
|
|
2344
|
-
return typeof arg === 'boolean';
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
function isNull(arg) {
|
|
2348
|
-
return arg === null;
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
function isNumber(arg) {
|
|
2352
|
-
return typeof arg === 'number';
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
function isString(arg) {
|
|
2356
|
-
return typeof arg === 'string';
|
|
2357
|
-
}
|
|
2358
|
-
|
|
2359
|
-
function isUndefined(arg) {
|
|
2360
|
-
return arg === void 0;
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
function isRegExp(re) {
|
|
2364
|
-
return isObject(re) && objectToString(re) === '[object RegExp]';
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
function isObject(arg) {
|
|
2368
|
-
return typeof arg === 'object' && arg !== null;
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
function isDate(d) {
|
|
2372
|
-
return isObject(d) && objectToString(d) === '[object Date]';
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
function isError(e) {
|
|
2376
|
-
return isObject(e) &&
|
|
2377
|
-
(objectToString(e) === '[object Error]' || e instanceof Error);
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
function isFunction(arg) {
|
|
2381
|
-
return typeof arg === 'function';
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
function isPrimitive(arg) {
|
|
2385
|
-
return arg === null ||
|
|
2386
|
-
typeof arg === 'boolean' ||
|
|
2387
|
-
typeof arg === 'number' ||
|
|
2388
|
-
typeof arg === 'string' ||
|
|
2389
|
-
typeof arg === 'symbol' || // ES6 symbol
|
|
2390
|
-
typeof arg === 'undefined';
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
function objectToString(o) {
|
|
2394
|
-
return Object.prototype.toString.call(o);
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
function _extend(origin, add) {
|
|
2398
|
-
// Don't do anything if add isn't an object
|
|
2399
|
-
if (!add || !isObject(add)) return origin;
|
|
2400
|
-
|
|
2401
|
-
var keys = Object.keys(add);
|
|
2402
|
-
var i = keys.length;
|
|
2403
|
-
while (i--) {
|
|
2404
|
-
origin[keys[i]] = add[keys[i]];
|
|
2405
|
-
}
|
|
2406
|
-
return origin;
|
|
2407
|
-
}
|
|
2408
|
-
function hasOwnProperty(obj, prop) {
|
|
2409
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
function compare(a, b) {
|
|
2413
|
-
if (a === b) {
|
|
2414
|
-
return 0;
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
var x = a.length;
|
|
2418
|
-
var y = b.length;
|
|
2419
|
-
|
|
2420
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
2421
|
-
if (a[i] !== b[i]) {
|
|
2422
|
-
x = a[i];
|
|
2423
|
-
y = b[i];
|
|
2424
|
-
break;
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
if (x < y) {
|
|
2429
|
-
return -1;
|
|
2430
|
-
}
|
|
2431
|
-
if (y < x) {
|
|
2432
|
-
return 1;
|
|
2433
|
-
}
|
|
2434
|
-
return 0;
|
|
2435
|
-
}
|
|
2436
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
|
2437
|
-
|
|
2438
|
-
var objectKeys = Object.keys || function (obj) {
|
|
2439
|
-
var keys = [];
|
|
2440
|
-
for (var key in obj) {
|
|
2441
|
-
if (hasOwn.call(obj, key)) keys.push(key);
|
|
2442
|
-
}
|
|
2443
|
-
return keys;
|
|
2444
|
-
};
|
|
2445
|
-
var pSlice = Array.prototype.slice;
|
|
2446
|
-
var _functionsHaveNames;
|
|
2447
|
-
function functionsHaveNames() {
|
|
2448
|
-
if (typeof _functionsHaveNames !== 'undefined') {
|
|
2449
|
-
return _functionsHaveNames;
|
|
2450
|
-
}
|
|
2451
|
-
return _functionsHaveNames = (function () {
|
|
2452
|
-
return function foo() {}.name === 'foo';
|
|
2453
|
-
}());
|
|
2454
|
-
}
|
|
2455
|
-
function pToString (obj) {
|
|
2456
|
-
return Object.prototype.toString.call(obj);
|
|
2457
|
-
}
|
|
2458
|
-
function isView(arrbuf) {
|
|
2459
|
-
if (isBuffer(arrbuf)) {
|
|
2460
|
-
return false;
|
|
2461
|
-
}
|
|
2462
|
-
if (typeof global$1.ArrayBuffer !== 'function') {
|
|
2463
|
-
return false;
|
|
2464
|
-
}
|
|
2465
|
-
if (typeof ArrayBuffer.isView === 'function') {
|
|
2466
|
-
return ArrayBuffer.isView(arrbuf);
|
|
2467
|
-
}
|
|
2468
|
-
if (!arrbuf) {
|
|
2469
|
-
return false;
|
|
2470
|
-
}
|
|
2471
|
-
if (arrbuf instanceof DataView) {
|
|
2472
|
-
return true;
|
|
2473
|
-
}
|
|
2474
|
-
if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
|
|
2475
|
-
return true;
|
|
2476
|
-
}
|
|
2477
|
-
return false;
|
|
2478
|
-
}
|
|
2479
|
-
// 1. The assert module provides functions that throw
|
|
2480
|
-
// AssertionError's when particular conditions are not met. The
|
|
2481
|
-
// assert module must conform to the following interface.
|
|
2482
|
-
|
|
2483
|
-
function assert(value, message) {
|
|
2484
|
-
if (!value) fail(value, true, message, '==', ok);
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
// 2. The AssertionError is defined in assert.
|
|
2488
|
-
// new assert.AssertionError({ message: message,
|
|
2489
|
-
// actual: actual,
|
|
2490
|
-
// expected: expected })
|
|
2491
|
-
|
|
2492
|
-
var regex = /\s*function\s+([^\(\s]*)\s*/;
|
|
2493
|
-
// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
|
|
2494
|
-
function getName(func) {
|
|
2495
|
-
if (!isFunction(func)) {
|
|
2496
|
-
return;
|
|
2497
|
-
}
|
|
2498
|
-
if (functionsHaveNames()) {
|
|
2499
|
-
return func.name;
|
|
2500
|
-
}
|
|
2501
|
-
var str = func.toString();
|
|
2502
|
-
var match = str.match(regex);
|
|
2503
|
-
return match && match[1];
|
|
2504
|
-
}
|
|
2505
|
-
assert.AssertionError = AssertionError;
|
|
2506
|
-
function AssertionError(options) {
|
|
2507
|
-
this.name = 'AssertionError';
|
|
2508
|
-
this.actual = options.actual;
|
|
2509
|
-
this.expected = options.expected;
|
|
2510
|
-
this.operator = options.operator;
|
|
2511
|
-
if (options.message) {
|
|
2512
|
-
this.message = options.message;
|
|
2513
|
-
this.generatedMessage = false;
|
|
2514
|
-
} else {
|
|
2515
|
-
this.message = getMessage(this);
|
|
2516
|
-
this.generatedMessage = true;
|
|
2517
|
-
}
|
|
2518
|
-
var stackStartFunction = options.stackStartFunction || fail;
|
|
2519
|
-
if (Error.captureStackTrace) {
|
|
2520
|
-
Error.captureStackTrace(this, stackStartFunction);
|
|
2521
|
-
} else {
|
|
2522
|
-
// non v8 browsers so we can have a stacktrace
|
|
2523
|
-
var err = new Error();
|
|
2524
|
-
if (err.stack) {
|
|
2525
|
-
var out = err.stack;
|
|
2526
|
-
|
|
2527
|
-
// try to strip useless frames
|
|
2528
|
-
var fn_name = getName(stackStartFunction);
|
|
2529
|
-
var idx = out.indexOf('\n' + fn_name);
|
|
2530
|
-
if (idx >= 0) {
|
|
2531
|
-
// once we have located the function frame
|
|
2532
|
-
// we need to strip out everything before it (and its line)
|
|
2533
|
-
var next_line = out.indexOf('\n', idx + 1);
|
|
2534
|
-
out = out.substring(next_line + 1);
|
|
2535
|
-
}
|
|
2536
|
-
|
|
2537
|
-
this.stack = out;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
|
-
// assert.AssertionError instanceof Error
|
|
2543
|
-
inherits(AssertionError, Error);
|
|
2544
|
-
|
|
2545
|
-
function truncate(s, n) {
|
|
2546
|
-
if (typeof s === 'string') {
|
|
2547
|
-
return s.length < n ? s : s.slice(0, n);
|
|
2548
|
-
} else {
|
|
2549
|
-
return s;
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
function inspect(something) {
|
|
2553
|
-
if (functionsHaveNames() || !isFunction(something)) {
|
|
2554
|
-
return inspect$1(something);
|
|
2555
|
-
}
|
|
2556
|
-
var rawname = getName(something);
|
|
2557
|
-
var name = rawname ? ': ' + rawname : '';
|
|
2558
|
-
return '[Function' + name + ']';
|
|
2559
|
-
}
|
|
2560
|
-
function getMessage(self) {
|
|
2561
|
-
return truncate(inspect(self.actual), 128) + ' ' +
|
|
2562
|
-
self.operator + ' ' +
|
|
2563
|
-
truncate(inspect(self.expected), 128);
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
// At present only the three keys mentioned above are used and
|
|
2567
|
-
// understood by the spec. Implementations or sub modules can pass
|
|
2568
|
-
// other keys to the AssertionError's constructor - they will be
|
|
2569
|
-
// ignored.
|
|
2570
|
-
|
|
2571
|
-
// 3. All of the following functions must throw an AssertionError
|
|
2572
|
-
// when a corresponding condition is not met, with a message that
|
|
2573
|
-
// may be undefined if not provided. All assertion methods provide
|
|
2574
|
-
// both the actual and expected values to the assertion error for
|
|
2575
|
-
// display purposes.
|
|
2576
|
-
|
|
2577
|
-
function fail(actual, expected, message, operator, stackStartFunction) {
|
|
2578
|
-
throw new AssertionError({
|
|
2579
|
-
message: message,
|
|
2580
|
-
actual: actual,
|
|
2581
|
-
expected: expected,
|
|
2582
|
-
operator: operator,
|
|
2583
|
-
stackStartFunction: stackStartFunction
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
// EXTENSION! allows for well behaved errors defined elsewhere.
|
|
2588
|
-
assert.fail = fail;
|
|
2589
|
-
|
|
2590
|
-
// 4. Pure assertion tests whether a value is truthy, as determined
|
|
2591
|
-
// by !!guard.
|
|
2592
|
-
// assert.ok(guard, message_opt);
|
|
2593
|
-
// This statement is equivalent to assert.equal(true, !!guard,
|
|
2594
|
-
// message_opt);. To test strictly for the value true, use
|
|
2595
|
-
// assert.strictEqual(true, guard, message_opt);.
|
|
2596
|
-
|
|
2597
|
-
function ok(value, message) {
|
|
2598
|
-
if (!value) fail(value, true, message, '==', ok);
|
|
2599
|
-
}
|
|
2600
|
-
assert.ok = ok;
|
|
2601
|
-
|
|
2602
|
-
// 5. The equality assertion tests shallow, coercive equality with
|
|
2603
|
-
// ==.
|
|
2604
|
-
// assert.equal(actual, expected, message_opt);
|
|
2605
|
-
assert.equal = equal;
|
|
2606
|
-
function equal(actual, expected, message) {
|
|
2607
|
-
if (actual != expected) fail(actual, expected, message, '==', equal);
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
|
-
// 6. The non-equality assertion tests for whether two objects are not equal
|
|
2611
|
-
// with != assert.notEqual(actual, expected, message_opt);
|
|
2612
|
-
assert.notEqual = notEqual;
|
|
2613
|
-
function notEqual(actual, expected, message) {
|
|
2614
|
-
if (actual == expected) {
|
|
2615
|
-
fail(actual, expected, message, '!=', notEqual);
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
// 7. The equivalence assertion tests a deep equality relation.
|
|
2620
|
-
// assert.deepEqual(actual, expected, message_opt);
|
|
2621
|
-
assert.deepEqual = deepEqual;
|
|
2622
|
-
function deepEqual(actual, expected, message) {
|
|
2623
|
-
if (!_deepEqual(actual, expected, false)) {
|
|
2624
|
-
fail(actual, expected, message, 'deepEqual', deepEqual);
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
assert.deepStrictEqual = deepStrictEqual;
|
|
2628
|
-
function deepStrictEqual(actual, expected, message) {
|
|
2629
|
-
if (!_deepEqual(actual, expected, true)) {
|
|
2630
|
-
fail(actual, expected, message, 'deepStrictEqual', deepStrictEqual);
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
function _deepEqual(actual, expected, strict, memos) {
|
|
2635
|
-
// 7.1. All identical values are equivalent, as determined by ===.
|
|
2636
|
-
if (actual === expected) {
|
|
2637
|
-
return true;
|
|
2638
|
-
} else if (isBuffer(actual) && isBuffer(expected)) {
|
|
2639
|
-
return compare(actual, expected) === 0;
|
|
2640
|
-
|
|
2641
|
-
// 7.2. If the expected value is a Date object, the actual value is
|
|
2642
|
-
// equivalent if it is also a Date object that refers to the same time.
|
|
2643
|
-
} else if (isDate(actual) && isDate(expected)) {
|
|
2644
|
-
return actual.getTime() === expected.getTime();
|
|
2645
|
-
|
|
2646
|
-
// 7.3 If the expected value is a RegExp object, the actual value is
|
|
2647
|
-
// equivalent if it is also a RegExp object with the same source and
|
|
2648
|
-
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
|
|
2649
|
-
} else if (isRegExp(actual) && isRegExp(expected)) {
|
|
2650
|
-
return actual.source === expected.source &&
|
|
2651
|
-
actual.global === expected.global &&
|
|
2652
|
-
actual.multiline === expected.multiline &&
|
|
2653
|
-
actual.lastIndex === expected.lastIndex &&
|
|
2654
|
-
actual.ignoreCase === expected.ignoreCase;
|
|
2655
|
-
|
|
2656
|
-
// 7.4. Other pairs that do not both pass typeof value == 'object',
|
|
2657
|
-
// equivalence is determined by ==.
|
|
2658
|
-
} else if ((actual === null || typeof actual !== 'object') &&
|
|
2659
|
-
(expected === null || typeof expected !== 'object')) {
|
|
2660
|
-
return strict ? actual === expected : actual == expected;
|
|
2661
|
-
|
|
2662
|
-
// If both values are instances of typed arrays, wrap their underlying
|
|
2663
|
-
// ArrayBuffers in a Buffer each to increase performance
|
|
2664
|
-
// This optimization requires the arrays to have the same type as checked by
|
|
2665
|
-
// Object.prototype.toString (aka pToString). Never perform binary
|
|
2666
|
-
// comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
|
|
2667
|
-
// bit patterns are not identical.
|
|
2668
|
-
} else if (isView(actual) && isView(expected) &&
|
|
2669
|
-
pToString(actual) === pToString(expected) &&
|
|
2670
|
-
!(actual instanceof Float32Array ||
|
|
2671
|
-
actual instanceof Float64Array)) {
|
|
2672
|
-
return compare(new Uint8Array(actual.buffer),
|
|
2673
|
-
new Uint8Array(expected.buffer)) === 0;
|
|
2674
|
-
|
|
2675
|
-
// 7.5 For all other Object pairs, including Array objects, equivalence is
|
|
2676
|
-
// determined by having the same number of owned properties (as verified
|
|
2677
|
-
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
|
2678
|
-
// (although not necessarily the same order), equivalent values for every
|
|
2679
|
-
// corresponding key, and an identical 'prototype' property. Note: this
|
|
2680
|
-
// accounts for both named and indexed properties on Arrays.
|
|
2681
|
-
} else if (isBuffer(actual) !== isBuffer(expected)) {
|
|
2682
|
-
return false;
|
|
2683
|
-
} else {
|
|
2684
|
-
memos = memos || {actual: [], expected: []};
|
|
2685
|
-
|
|
2686
|
-
var actualIndex = memos.actual.indexOf(actual);
|
|
2687
|
-
if (actualIndex !== -1) {
|
|
2688
|
-
if (actualIndex === memos.expected.indexOf(expected)) {
|
|
2689
|
-
return true;
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
memos.actual.push(actual);
|
|
2694
|
-
memos.expected.push(expected);
|
|
2695
|
-
|
|
2696
|
-
return objEquiv(actual, expected, strict, memos);
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
function isArguments(object) {
|
|
2701
|
-
return Object.prototype.toString.call(object) == '[object Arguments]';
|
|
2702
|
-
}
|
|
2703
|
-
|
|
2704
|
-
function objEquiv(a, b, strict, actualVisitedObjects) {
|
|
2705
|
-
if (a === null || a === undefined || b === null || b === undefined)
|
|
2706
|
-
return false;
|
|
2707
|
-
// if one is a primitive, the other must be same
|
|
2708
|
-
if (isPrimitive(a) || isPrimitive(b))
|
|
2709
|
-
return a === b;
|
|
2710
|
-
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
|
2711
|
-
return false;
|
|
2712
|
-
var aIsArgs = isArguments(a);
|
|
2713
|
-
var bIsArgs = isArguments(b);
|
|
2714
|
-
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
|
2715
|
-
return false;
|
|
2716
|
-
if (aIsArgs) {
|
|
2717
|
-
a = pSlice.call(a);
|
|
2718
|
-
b = pSlice.call(b);
|
|
2719
|
-
return _deepEqual(a, b, strict);
|
|
2720
|
-
}
|
|
2721
|
-
var ka = objectKeys(a);
|
|
2722
|
-
var kb = objectKeys(b);
|
|
2723
|
-
var key, i;
|
|
2724
|
-
// having the same number of owned properties (keys incorporates
|
|
2725
|
-
// hasOwnProperty)
|
|
2726
|
-
if (ka.length !== kb.length)
|
|
2727
|
-
return false;
|
|
2728
|
-
//the same set of keys (although not necessarily the same order),
|
|
2729
|
-
ka.sort();
|
|
2730
|
-
kb.sort();
|
|
2731
|
-
//~~~cheap key test
|
|
2732
|
-
for (i = ka.length - 1; i >= 0; i--) {
|
|
2733
|
-
if (ka[i] !== kb[i])
|
|
2734
|
-
return false;
|
|
2735
|
-
}
|
|
2736
|
-
//equivalent values for every corresponding key, and
|
|
2737
|
-
//~~~possibly expensive deep test
|
|
2738
|
-
for (i = ka.length - 1; i >= 0; i--) {
|
|
2739
|
-
key = ka[i];
|
|
2740
|
-
if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
|
|
2741
|
-
return false;
|
|
2742
|
-
}
|
|
2743
|
-
return true;
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
// 8. The non-equivalence assertion tests for any deep inequality.
|
|
2747
|
-
// assert.notDeepEqual(actual, expected, message_opt);
|
|
2748
|
-
assert.notDeepEqual = notDeepEqual;
|
|
2749
|
-
function notDeepEqual(actual, expected, message) {
|
|
2750
|
-
if (_deepEqual(actual, expected, false)) {
|
|
2751
|
-
fail(actual, expected, message, 'notDeepEqual', notDeepEqual);
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
|
|
2755
|
-
assert.notDeepStrictEqual = notDeepStrictEqual;
|
|
2756
|
-
function notDeepStrictEqual(actual, expected, message) {
|
|
2757
|
-
if (_deepEqual(actual, expected, true)) {
|
|
2758
|
-
fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
// 9. The strict equality assertion tests strict equality, as determined by ===.
|
|
2764
|
-
// assert.strictEqual(actual, expected, message_opt);
|
|
2765
|
-
assert.strictEqual = strictEqual;
|
|
2766
|
-
function strictEqual(actual, expected, message) {
|
|
2767
|
-
if (actual !== expected) {
|
|
2768
|
-
fail(actual, expected, message, '===', strictEqual);
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
|
|
2772
|
-
// 10. The strict non-equality assertion tests for strict inequality, as
|
|
2773
|
-
// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
|
|
2774
|
-
assert.notStrictEqual = notStrictEqual;
|
|
2775
|
-
function notStrictEqual(actual, expected, message) {
|
|
2776
|
-
if (actual === expected) {
|
|
2777
|
-
fail(actual, expected, message, '!==', notStrictEqual);
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
function expectedException(actual, expected) {
|
|
2782
|
-
if (!actual || !expected) {
|
|
2783
|
-
return false;
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
|
-
if (Object.prototype.toString.call(expected) == '[object RegExp]') {
|
|
2787
|
-
return expected.test(actual);
|
|
2788
|
-
}
|
|
2789
|
-
|
|
2790
|
-
try {
|
|
2791
|
-
if (actual instanceof expected) {
|
|
2792
|
-
return true;
|
|
2793
|
-
}
|
|
2794
|
-
} catch (e) {
|
|
2795
|
-
// Ignore. The instanceof check doesn't work for arrow functions.
|
|
2796
|
-
}
|
|
2797
|
-
|
|
2798
|
-
if (Error.isPrototypeOf(expected)) {
|
|
2799
|
-
return false;
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2802
|
-
return expected.call({}, actual) === true;
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
function _tryBlock(block) {
|
|
2806
|
-
var error;
|
|
2807
|
-
try {
|
|
2808
|
-
block();
|
|
2809
|
-
} catch (e) {
|
|
2810
|
-
error = e;
|
|
2811
|
-
}
|
|
2812
|
-
return error;
|
|
2813
|
-
}
|
|
2814
|
-
|
|
2815
|
-
function _throws(shouldThrow, block, expected, message) {
|
|
2816
|
-
var actual;
|
|
2817
|
-
|
|
2818
|
-
if (typeof block !== 'function') {
|
|
2819
|
-
throw new TypeError('"block" argument must be a function');
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
|
-
if (typeof expected === 'string') {
|
|
2823
|
-
message = expected;
|
|
2824
|
-
expected = null;
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
actual = _tryBlock(block);
|
|
2828
|
-
|
|
2829
|
-
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
|
2830
|
-
(message ? ' ' + message : '.');
|
|
2831
|
-
|
|
2832
|
-
if (shouldThrow && !actual) {
|
|
2833
|
-
fail(actual, expected, 'Missing expected exception' + message);
|
|
2834
|
-
}
|
|
2835
|
-
|
|
2836
|
-
var userProvidedMessage = typeof message === 'string';
|
|
2837
|
-
var isUnwantedException = !shouldThrow && isError(actual);
|
|
2838
|
-
var isUnexpectedException = !shouldThrow && actual && !expected;
|
|
2839
|
-
|
|
2840
|
-
if ((isUnwantedException &&
|
|
2841
|
-
userProvidedMessage &&
|
|
2842
|
-
expectedException(actual, expected)) ||
|
|
2843
|
-
isUnexpectedException) {
|
|
2844
|
-
fail(actual, expected, 'Got unwanted exception' + message);
|
|
2845
|
-
}
|
|
2846
|
-
|
|
2847
|
-
if ((shouldThrow && actual && expected &&
|
|
2848
|
-
!expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
|
2849
|
-
throw actual;
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
|
|
2853
|
-
// 11. Expected to throw an error:
|
|
2854
|
-
// assert.throws(block, Error_opt, message_opt);
|
|
2855
|
-
assert.throws = throws;
|
|
2856
|
-
function throws(block, /*optional*/error, /*optional*/message) {
|
|
2857
|
-
_throws(true, block, error, message);
|
|
2858
|
-
}
|
|
2859
|
-
|
|
2860
|
-
// EXTENSION! This is annoying to write outside this module.
|
|
2861
|
-
assert.doesNotThrow = doesNotThrow;
|
|
2862
|
-
function doesNotThrow(block, /*optional*/error, /*optional*/message) {
|
|
2863
|
-
_throws(false, block, error, message);
|
|
2864
|
-
}
|
|
2865
|
-
|
|
2866
|
-
assert.ifError = ifError;
|
|
2867
|
-
function ifError(err) {
|
|
2868
|
-
if (err) throw err;
|
|
2869
|
-
}
|
|
2870
|
-
|
|
2871
|
-
const tracer = {
|
|
2872
|
-
trace: () => { },
|
|
2873
|
-
reportError: () => { },
|
|
2874
|
-
};
|
|
2875
|
-
/**
|
|
2876
|
-
* @public
|
|
2877
|
-
* Sets a tracer implementation, e.g., LogTracer or SentryTracer
|
|
2878
|
-
*/
|
|
2879
|
-
function setTracer(t) {
|
|
2880
|
-
tracer.trace = t.trace.bind(t);
|
|
2881
|
-
tracer.reportError = t.reportError.bind(t);
|
|
2882
|
-
}
|
|
2883
|
-
/**
|
|
2884
|
-
* @public
|
|
2885
|
-
* @param e
|
|
2886
|
-
*/
|
|
2887
|
-
function reportError(e) {
|
|
2888
|
-
tracer.reportError(e);
|
|
2889
|
-
}
|
|
2890
|
-
/**
|
|
2891
|
-
* @public
|
|
2892
|
-
* @param msg
|
|
2893
|
-
* @param data
|
|
2894
|
-
*/
|
|
2895
|
-
function trace(msg, data = {}) {
|
|
2896
|
-
tracer.trace(msg, data);
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
var PlayerEvent;
|
|
2900
|
-
(function (PlayerEvent) {
|
|
2901
|
-
PlayerEvent["Ready"] = "ready";
|
|
2902
|
-
PlayerEvent["Play"] = "play";
|
|
2903
|
-
PlayerEvent["Pause"] = "pause";
|
|
2904
|
-
PlayerEvent["Stop"] = "stop";
|
|
2905
|
-
PlayerEvent["Ended"] = "ended";
|
|
2906
|
-
})(PlayerEvent || (PlayerEvent = {}));
|
|
2907
|
-
const T = "Player";
|
|
2908
|
-
const DEFAULT_OPTIONS = {
|
|
2909
|
-
autoPlay: false,
|
|
2910
|
-
mute: false,
|
|
2911
|
-
loop: false,
|
|
2912
|
-
};
|
|
2913
|
-
/**
|
|
2914
|
-
* @beta
|
|
2915
|
-
*/
|
|
2916
|
-
class Player {
|
|
2917
|
-
emitter = new EventLite();
|
|
2918
|
-
player = null;
|
|
2919
|
-
pluginLoaders = [];
|
|
2920
|
-
clapprReady = false;
|
|
2921
|
-
timer = null;
|
|
2922
|
-
tuneInEntered = false;
|
|
2923
|
-
supportedMediaTransports = [];
|
|
2924
|
-
config;
|
|
2925
|
-
get playing() {
|
|
2926
|
-
return this.player ? this.player.isPlaying() : false;
|
|
2927
|
-
}
|
|
2928
|
-
get ready() {
|
|
2929
|
-
return this.clapprReady;
|
|
2930
|
-
}
|
|
2931
|
-
constructor(config) {
|
|
2932
|
-
this.config = $.extend(true, {}, DEFAULT_OPTIONS, config);
|
|
2933
|
-
}
|
|
2934
|
-
on(event, handler) {
|
|
2935
|
-
this.emitter.on(event, handler);
|
|
2936
|
-
}
|
|
2937
|
-
off(event, handler) {
|
|
2938
|
-
this.emitter.off(event, handler);
|
|
2939
|
-
}
|
|
2940
|
-
async init(playerElement) {
|
|
2941
|
-
assert.ok(!this.player, 'Player already initialized');
|
|
2942
|
-
assert.ok(playerElement, 'Player element is required');
|
|
2943
|
-
if (this.config.debug === 'all' ||
|
|
2944
|
-
this.config.debug === 'clappr') {
|
|
2945
|
-
Log.setLevel(0);
|
|
2946
|
-
}
|
|
2947
|
-
Log.debug('Config', this.config);
|
|
2948
|
-
this.configurePlugins();
|
|
2949
|
-
return this.loadPlugins().then(async () => {
|
|
2950
|
-
const coreOpts = this.buildCoreOptions(playerElement);
|
|
2951
|
-
const { core, container, } = Loader.registeredPlugins;
|
|
2952
|
-
coreOpts.plugins = {
|
|
2953
|
-
core: Object.values(core),
|
|
2954
|
-
container: Object.values(container),
|
|
2955
|
-
playback: Loader.registeredPlaybacks,
|
|
2956
|
-
};
|
|
2957
|
-
console.log('plugins', coreOpts.plugins);
|
|
2958
|
-
return this.initPlayer(coreOpts);
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
destroy() {
|
|
2962
|
-
trace(`${T} destroy`, { player: !!this.player });
|
|
2963
|
-
if (this.player) {
|
|
2964
|
-
this.player.destroy();
|
|
2965
|
-
this.player = null;
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
pause() {
|
|
2969
|
-
assert.ok(this.player, 'Player not initialized');
|
|
2970
|
-
this.player.pause();
|
|
2971
|
-
}
|
|
2972
|
-
play() {
|
|
2973
|
-
assert.ok(this.player, 'Player not initialized');
|
|
2974
|
-
this.player.play();
|
|
2975
|
-
}
|
|
2976
|
-
seekTo(time) {
|
|
2977
|
-
assert.ok(this.player, 'Player not initialized');
|
|
2978
|
-
this.player.seek(time);
|
|
2979
|
-
}
|
|
2980
|
-
stop() {
|
|
2981
|
-
assert.ok(this.player, 'Player not initialized');
|
|
2982
|
-
this.player.stop();
|
|
2983
|
-
}
|
|
2984
|
-
static registerPlugin(plugin) {
|
|
2985
|
-
Loader.registerPlugin(plugin);
|
|
2986
|
-
}
|
|
2987
|
-
loadPlugins() {
|
|
2988
|
-
return Promise.all(this.pluginLoaders.map((loader) => loader())).then(() => { });
|
|
2989
|
-
}
|
|
2990
|
-
initPlayer(coreOptions) {
|
|
2991
|
-
assert.ok(!this.player, 'Player already initialized');
|
|
2992
|
-
const player = new Player$1(coreOptions);
|
|
2993
|
-
this.player = player;
|
|
2994
|
-
this.timer = globalThis.setTimeout(() => {
|
|
2995
|
-
try {
|
|
2996
|
-
if (!this.clapprReady &&
|
|
2997
|
-
player.core &&
|
|
2998
|
-
player.core
|
|
2999
|
-
.activePlayback) {
|
|
3000
|
-
this.tuneIn();
|
|
3001
|
-
// player.onReady = null; // TODO ?
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
catch (e) {
|
|
3005
|
-
reportError(e);
|
|
3006
|
-
}
|
|
3007
|
-
}, 4000);
|
|
3008
|
-
}
|
|
3009
|
-
// TODO sort this out
|
|
3010
|
-
async tuneIn() {
|
|
3011
|
-
assert.ok(this.player);
|
|
3012
|
-
trace(`${T} tuneIn enter`, {
|
|
3013
|
-
ready: this.clapprReady,
|
|
3014
|
-
tuneInEntered: this.tuneInEntered,
|
|
3015
|
-
});
|
|
3016
|
-
if (this.tuneInEntered) {
|
|
3017
|
-
return;
|
|
3018
|
-
}
|
|
3019
|
-
this.tuneInEntered = true;
|
|
3020
|
-
const player = this.player;
|
|
3021
|
-
if (Browser.isiOS &&
|
|
3022
|
-
player.core.activePlayback) {
|
|
3023
|
-
player.core.activePlayback.$el.on('webkitendfullscreen', () => {
|
|
3024
|
-
try {
|
|
3025
|
-
player.core.handleFullscreenChange();
|
|
3026
|
-
}
|
|
3027
|
-
catch (e) {
|
|
3028
|
-
reportError(e);
|
|
3029
|
-
}
|
|
3030
|
-
});
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
configurePlugins() {
|
|
3034
|
-
if (!Browser.isiOS && this.config.multisources.some((el) => el.sourceDash)) {
|
|
3035
|
-
this.scheduleLoad(async () => {
|
|
3036
|
-
const module = await import('./DashPlayback-oVlZkeUP.js');
|
|
3037
|
-
Loader.registerPlayback(module.default);
|
|
3038
|
-
});
|
|
3039
|
-
}
|
|
3040
|
-
// TODO remove !isiOS?
|
|
3041
|
-
// if (!Browser.isiOS && this.config.multisources.some((el) => el.hls_mpegts_url)) {
|
|
3042
|
-
if (this.config.multisources.some((el) => el.hlsMpegtsUrl || el.hlsCmafUrl || el.source.endsWith('.m3u8'))) {
|
|
3043
|
-
this.scheduleLoad(async () => {
|
|
3044
|
-
const module = await import('./HlsPlayback-CYDGVQC4.js');
|
|
3045
|
-
Loader.registerPlayback(module.default);
|
|
3046
|
-
});
|
|
3047
|
-
}
|
|
3048
|
-
}
|
|
3049
|
-
events = {
|
|
3050
|
-
onReady: () => {
|
|
3051
|
-
if (this.clapprReady) {
|
|
3052
|
-
return;
|
|
3053
|
-
}
|
|
3054
|
-
this.clapprReady = true;
|
|
3055
|
-
if (this.timer) {
|
|
3056
|
-
clearTimeout(this.timer);
|
|
3057
|
-
this.timer = null;
|
|
3058
|
-
}
|
|
3059
|
-
trace(`${T} onReady`);
|
|
3060
|
-
setTimeout(() => this.tuneIn(), 0);
|
|
3061
|
-
try {
|
|
3062
|
-
this.emitter.emit(PlayerEvent.Ready);
|
|
3063
|
-
}
|
|
3064
|
-
catch (e) {
|
|
3065
|
-
reportError(e);
|
|
3066
|
-
}
|
|
3067
|
-
},
|
|
3068
|
-
onPlay: () => {
|
|
3069
|
-
try {
|
|
3070
|
-
this.emitter.emit(PlayerEvent.Play);
|
|
3071
|
-
}
|
|
3072
|
-
catch (e) {
|
|
3073
|
-
reportError(e);
|
|
3074
|
-
}
|
|
3075
|
-
},
|
|
3076
|
-
onPause: () => {
|
|
3077
|
-
try {
|
|
3078
|
-
this.emitter.emit(PlayerEvent.Pause);
|
|
3079
|
-
}
|
|
3080
|
-
catch (e) {
|
|
3081
|
-
reportError(e);
|
|
3082
|
-
}
|
|
3083
|
-
},
|
|
3084
|
-
onEnded: () => {
|
|
3085
|
-
try {
|
|
3086
|
-
this.emitter.emit(PlayerEvent.Ended);
|
|
3087
|
-
}
|
|
3088
|
-
catch (e) {
|
|
3089
|
-
reportError(e);
|
|
3090
|
-
}
|
|
3091
|
-
},
|
|
3092
|
-
onStop: () => {
|
|
3093
|
-
try {
|
|
3094
|
-
this.emitter.emit(PlayerEvent.Stop);
|
|
3095
|
-
}
|
|
3096
|
-
catch (e) {
|
|
3097
|
-
reportError(e);
|
|
3098
|
-
}
|
|
3099
|
-
},
|
|
3100
|
-
};
|
|
3101
|
-
buildCoreOptions(playerElement) {
|
|
3102
|
-
this.checkMediaTransportsSupport();
|
|
3103
|
-
const multisources = this.processMultisources(this.config.priorityTransport);
|
|
3104
|
-
const mediaSources = multisources.map(ms => ms.source);
|
|
3105
|
-
const mainSource = this.findMainSource();
|
|
3106
|
-
const mainSourceUrl = unwrapSource(mainSource ? this.selectMediaTransport(mainSource, this.config.priorityTransport) : undefined);
|
|
3107
|
-
const poster = mainSource?.poster ?? this.config.poster;
|
|
3108
|
-
const coreOptions = {
|
|
3109
|
-
autoPlay: this.config.autoPlay,
|
|
3110
|
-
debug: this.config.debug || 'none',
|
|
3111
|
-
events: this.events,
|
|
3112
|
-
multisources,
|
|
3113
|
-
mute: this.config.mute,
|
|
3114
|
-
...this.config.pluginSettings,
|
|
3115
|
-
playback: {
|
|
3116
|
-
controls: false,
|
|
3117
|
-
preload: Browser.isiOS ? 'metadata' : 'none',
|
|
3118
|
-
playInline: true,
|
|
3119
|
-
crossOrigin: 'anonymous', // TODO
|
|
3120
|
-
hlsjsConfig: {
|
|
3121
|
-
debug: this.config.debug === 'all' || this.config.debug === 'hls',
|
|
3122
|
-
},
|
|
3123
|
-
},
|
|
3124
|
-
parent: playerElement,
|
|
3125
|
-
playbackType: this.config.playbackType,
|
|
3126
|
-
poster,
|
|
3127
|
-
width: playerElement.clientWidth,
|
|
3128
|
-
height: playerElement.clientHeight,
|
|
3129
|
-
loop: this.config.loop,
|
|
3130
|
-
strings: this.config.strings,
|
|
3131
|
-
source: mainSourceUrl,
|
|
3132
|
-
sources: mediaSources,
|
|
3133
|
-
};
|
|
3134
|
-
trace(`${T} buildCoreOptions`, coreOptions);
|
|
3135
|
-
return coreOptions;
|
|
3136
|
-
}
|
|
3137
|
-
findMainSource() {
|
|
3138
|
-
return this.config.multisources.find(ms => ms.live !== false);
|
|
3139
|
-
}
|
|
3140
|
-
scheduleLoad(cb) {
|
|
3141
|
-
this.pluginLoaders.push(cb);
|
|
3142
|
-
}
|
|
3143
|
-
selectMediaTransport(ms, priorityTransport = ms.priorityTransport) {
|
|
3144
|
-
const cmafUrl = ms.hlsCmafUrl || ms.source; // source is default url for hls
|
|
3145
|
-
const mpegtsUrl = ms.hlsMpegtsUrl; // no-low-latency HLS
|
|
3146
|
-
const dashUrl = ms.sourceDash;
|
|
3147
|
-
const masterSource = ms.source;
|
|
3148
|
-
const mts = this.getAvailableTransportsPreference(priorityTransport);
|
|
3149
|
-
for (const mt of mts) {
|
|
3150
|
-
switch (mt) {
|
|
3151
|
-
case 'dash':
|
|
3152
|
-
if (dashUrl) {
|
|
3153
|
-
return dashUrl;
|
|
3154
|
-
}
|
|
3155
|
-
break;
|
|
3156
|
-
case 'hls':
|
|
3157
|
-
if (cmafUrl) {
|
|
3158
|
-
return cmafUrl;
|
|
3159
|
-
}
|
|
3160
|
-
break;
|
|
3161
|
-
default:
|
|
3162
|
-
return mpegtsUrl || masterSource;
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
// no supported transport found
|
|
3166
|
-
return '';
|
|
3167
|
-
}
|
|
3168
|
-
getAvailableTransportsPreference(priorityTransport) {
|
|
3169
|
-
const mtp = [];
|
|
3170
|
-
if (priorityTransport !== 'auto' && this.supportedMediaTransports.includes(priorityTransport)) {
|
|
3171
|
-
mtp.push(priorityTransport);
|
|
3172
|
-
}
|
|
3173
|
-
for (const mt of this.supportedMediaTransports) {
|
|
3174
|
-
if (mt !== priorityTransport) {
|
|
3175
|
-
mtp.push(mt);
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
return mtp;
|
|
3179
|
-
}
|
|
3180
|
-
checkMediaTransportsSupport() {
|
|
3181
|
-
const isDashSupported = typeof (globalThis.MediaSource || globalThis.WebKitMediaSource) === 'function';
|
|
3182
|
-
if (isDashSupported) {
|
|
3183
|
-
this.supportedMediaTransports.push('dash');
|
|
3184
|
-
}
|
|
3185
|
-
if (HLSJS.isSupported()) {
|
|
3186
|
-
this.supportedMediaTransports.push('hls');
|
|
3187
|
-
}
|
|
3188
|
-
this.supportedMediaTransports.push('mpegts');
|
|
3189
|
-
}
|
|
3190
|
-
processMultisources(transport) {
|
|
3191
|
-
return this.config.multisources.map((ms) => ({
|
|
3192
|
-
...ms,
|
|
3193
|
-
source: this.selectMediaTransport(ms, transport),
|
|
3194
|
-
})).filter((el) => !!el.source);
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
function unwrapSource(s) {
|
|
3198
|
-
if (!s) {
|
|
3199
|
-
return;
|
|
3200
|
-
}
|
|
3201
|
-
return typeof s === "string" ? s : s.source;
|
|
3202
|
-
}
|
|
3203
|
-
|
|
3204
|
-
function fromStreamMediaSourceDto(s) {
|
|
3205
|
-
return ({
|
|
3206
|
-
...s,
|
|
3207
|
-
hlsCmafUrl: s.hls_cmaf_url,
|
|
3208
|
-
hlsMpegtsUrl: s.hls_mpegts_url,
|
|
3209
|
-
priorityTransport: s.priority_transport,
|
|
3210
|
-
sourceDash: s.source_dash,
|
|
3211
|
-
vtt: s.vtt,
|
|
3212
|
-
});
|
|
3213
|
-
}
|
|
3214
|
-
|
|
3215
|
-
const APP_NAME = "gplayer";
|
|
3216
|
-
class DebuggerWrapper {
|
|
3217
|
-
writer;
|
|
3218
|
-
namespace;
|
|
3219
|
-
currentWriter;
|
|
3220
|
-
constructor(writer, namespace, enabled = true) {
|
|
3221
|
-
this.writer = writer;
|
|
3222
|
-
this.namespace = namespace;
|
|
3223
|
-
this.currentWriter = enabled ? writer : nullWriter;
|
|
3224
|
-
}
|
|
3225
|
-
enable() {
|
|
3226
|
-
this.currentWriter = this.writer;
|
|
3227
|
-
}
|
|
3228
|
-
disable() {
|
|
3229
|
-
this.currentWriter = nullWriter;
|
|
3230
|
-
}
|
|
3231
|
-
write = (m, ...args) => {
|
|
3232
|
-
const tokens = args.map((_) => "%s");
|
|
3233
|
-
if (typeof m === "string" || args.length > 0) {
|
|
3234
|
-
tokens.unshift("%s");
|
|
3235
|
-
}
|
|
3236
|
-
this.currentWriter(`${this.namespace}: ${tokens.join(' ')}`, m, ...args.map(a => JSON.stringify(a)));
|
|
3237
|
-
};
|
|
3238
|
-
}
|
|
3239
|
-
const currentPatterns = [];
|
|
3240
|
-
function parsePattern(pattern) {
|
|
3241
|
-
if (pattern === "*") {
|
|
3242
|
-
return /.?/;
|
|
3243
|
-
}
|
|
3244
|
-
return new RegExp("^" + pattern.replace(/\*/g, "[@\\w-]+"), "i");
|
|
3245
|
-
}
|
|
3246
|
-
function pass(namespace) {
|
|
3247
|
-
return currentPatterns.some((p) => p.test(namespace));
|
|
3248
|
-
}
|
|
3249
|
-
function nullWriter() { }
|
|
3250
|
-
/**
|
|
3251
|
-
* Logging utility with [debug](https://www.npmjs.com/package/debug)-like API
|
|
3252
|
-
* @beta
|
|
3253
|
-
*/
|
|
3254
|
-
class Logger {
|
|
3255
|
-
info;
|
|
3256
|
-
warn;
|
|
3257
|
-
error;
|
|
3258
|
-
debug;
|
|
3259
|
-
static items = [];
|
|
3260
|
-
constructor(namespace, appName = APP_NAME) {
|
|
3261
|
-
const ns = namespace ? `:${namespace}` : "";
|
|
3262
|
-
const info = new DebuggerWrapper(console.info.bind(console), `${appName}:INFO${ns}`, pass(namespace));
|
|
3263
|
-
this.info = info.write;
|
|
3264
|
-
const warn = new DebuggerWrapper(console.warn.bind(console), `${appName}:WARN${ns}`, pass(namespace));
|
|
3265
|
-
this.warn = warn.write;
|
|
3266
|
-
const error = new DebuggerWrapper(console.error.bind(console), `${appName}:ERROR${ns}`, pass(namespace));
|
|
3267
|
-
this.error = error.write;
|
|
3268
|
-
const debug = new DebuggerWrapper(console.debug.bind(console), `${appName}:DEBUG${ns}`, pass(namespace));
|
|
3269
|
-
this.debug = debug.write;
|
|
3270
|
-
Logger.items.push(warn);
|
|
3271
|
-
Logger.items.push(info);
|
|
3272
|
-
Logger.items.push(error);
|
|
3273
|
-
Logger.items.push(debug);
|
|
3274
|
-
}
|
|
3275
|
-
/**
|
|
3276
|
-
* @param patterns - comma-separated list of patterns, can contain '*' as a wildcard
|
|
3277
|
-
*/
|
|
3278
|
-
static enable(patterns) {
|
|
3279
|
-
currentPatterns.splice(0, currentPatterns.length, ...patterns.split(",").filter(Boolean).map(parsePattern));
|
|
3280
|
-
Logger.toggleItems();
|
|
3281
|
-
}
|
|
3282
|
-
static disable() {
|
|
3283
|
-
currentPatterns.splice(0, currentPatterns.length);
|
|
3284
|
-
}
|
|
3285
|
-
static toggleItems() {
|
|
3286
|
-
for (const w of Logger.items) {
|
|
3287
|
-
if (pass(w.namespace)) {
|
|
3288
|
-
w.enable();
|
|
3289
|
-
}
|
|
3290
|
-
else {
|
|
3291
|
-
w.disable();
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
|
|
3297
|
-
/**
|
|
3298
|
-
* A tracer that logs to the console
|
|
3299
|
-
* @public
|
|
3300
|
-
*/
|
|
3301
|
-
class LogTracer {
|
|
3302
|
-
logger;
|
|
3303
|
-
constructor(ns = "") {
|
|
3304
|
-
this.logger = new Logger(ns);
|
|
3305
|
-
}
|
|
3306
|
-
reportError(e) {
|
|
3307
|
-
this.logger.error(e);
|
|
3308
|
-
}
|
|
3309
|
-
trace(msg, data) {
|
|
3310
|
-
this.logger.debug(msg, data);
|
|
3311
|
-
}
|
|
3312
|
-
}
|
|
3313
|
-
|
|
3314
|
-
/**
|
|
3315
|
-
* @beta
|
|
3316
|
-
*/
|
|
3317
|
-
class SentryTracer {
|
|
3318
|
-
client;
|
|
3319
|
-
constructor(client) {
|
|
3320
|
-
this.client = client;
|
|
3321
|
-
}
|
|
3322
|
-
reportError(e) {
|
|
3323
|
-
this.client.captureException(e);
|
|
3324
|
-
}
|
|
3325
|
-
trace(msg, data) {
|
|
3326
|
-
this.client.captureMessage(msg, "info", {
|
|
3327
|
-
data,
|
|
3328
|
-
});
|
|
3329
|
-
}
|
|
3330
|
-
}
|
|
3331
|
-
|
|
3332
|
-
export { LogTracer as L, PlayerEvent as P, SentryTracer as S, assert as a, Player as b, Logger as c, fromStreamMediaSourceDto as f, reportError as r, setTracer as s, trace as t };
|