@dxos/esbuild-plugins 2.28.3-dev.08b5c548 → 2.28.3-dev.22b82fa7

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