@dxos/esbuild-plugins 2.28.3-dev.e4579238 → 2.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +8 -0
- package/.rush/temp/package-deps_build_test.json +18 -0
- package/.rush/temp/shrinkwrap-deps.json +186 -5
- package/dist/src/index.d.ts +2 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/node-globals-polyfill-plugin.js +1 -1
- package/dist/src/node-globals-polyfill-plugin.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/esbuild-plugins.build.log +10 -0
- package/package.json +12 -10
- package/polyfills/Buffer.js +1951 -1950
- package/polyfills/process.js +147 -137
- package/src/index.ts +2 -3
- package/src/node-globals-polyfill-plugin.ts +1 -1
- package/tsconfig.json +0 -4
- package/.rush/temp/package-deps_build.json +0 -17
- package/.rush/temp/package-deps_build:test.json +0 -17
- package/.rush/temp/package-deps_prerelease.json +0 -17
package/polyfills/Buffer.js
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function base64toByteArray(b64) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function tripletToBase64(num) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function encodeChunk(uint8, start, end) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function fromByteArray(uint8) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
170
|
+
function kMaxLength () {
|
|
171
|
+
return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff;
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
function createBuffer(that, length) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
210
|
-
|
|
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
|
-
|
|
226
|
-
|
|
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
|
-
|
|
231
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
|
233
|
+
return fromArrayBuffer(that, value, encodingOrOffset, length);
|
|
234
|
+
}
|
|
237
235
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
if (typeof value === 'string') {
|
|
237
|
+
return fromString(that, value, encodingOrOffset);
|
|
238
|
+
}
|
|
241
239
|
|
|
242
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function assertSize(size) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function alloc(that, size, fill, encoding) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
305
|
-
}
|
|
301
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
302
|
+
return alloc(null, size, fill, encoding);
|
|
303
|
+
};
|
|
306
304
|
|
|
307
|
-
function allocUnsafe(that, size) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
329
|
-
}
|
|
326
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
327
|
+
return allocUnsafe(null, size);
|
|
328
|
+
};
|
|
330
329
|
|
|
331
|
-
function fromString(that, string, encoding) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
function fromString (that, string, encoding) {
|
|
331
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
332
|
+
encoding = 'utf8';
|
|
333
|
+
}
|
|
335
334
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
336
|
+
throw new TypeError('"encoding" must be a valid string encoding');
|
|
337
|
+
}
|
|
339
338
|
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
var length = byteLength(string, encoding) | 0;
|
|
340
|
+
that = createBuffer(that, length);
|
|
342
341
|
|
|
343
|
-
|
|
342
|
+
var actual = that.write(string, encoding);
|
|
344
343
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
351
|
+
return that;
|
|
353
352
|
}
|
|
354
353
|
|
|
355
|
-
function fromArrayLike(that, array) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
363
|
+
function fromArrayBuffer (that, array, byteOffset, length) {
|
|
364
|
+
array.byteLength; // this throws if `array` is not a valid ArrayBuffer
|
|
366
365
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
366
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
367
|
+
throw new RangeError('\'offset\' is out of bounds');
|
|
368
|
+
}
|
|
370
369
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
370
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
371
|
+
throw new RangeError('\'length\' is out of bounds');
|
|
372
|
+
}
|
|
374
373
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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.
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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
|
-
|
|
507
|
-
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
-
|
|
528
|
-
if (internalIsBuffer(string)) {
|
|
529
|
-
return string.length
|
|
530
|
-
}
|
|
406
|
+
if (obj) {
|
|
531
407
|
if (
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
408
|
+
(typeof ArrayBuffer !== 'undefined' &&
|
|
409
|
+
obj.buffer instanceof ArrayBuffer) ||
|
|
410
|
+
'length' in obj
|
|
535
411
|
) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
Buffer.prototype.swap16 = function swap16() {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
Buffer.prototype.swap32 = function swap32() {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
Buffer.prototype.swap64 = function swap64() {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
Buffer.prototype.toString = function toString() {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
Buffer.prototype.equals = function equals(b) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
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
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
-
|
|
916
|
+
return -1;
|
|
916
917
|
}
|
|
917
918
|
|
|
918
|
-
Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
919
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
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
|
-
|
|
943
|
-
|
|
944
|
-
|
|
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
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
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
|
|
967
|
-
|
|
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
|
|
971
|
-
|
|
967
|
+
function asciiWrite (buf, string, offset, length) {
|
|
968
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
972
969
|
}
|
|
973
970
|
|
|
974
|
-
function
|
|
975
|
-
|
|
971
|
+
function latin1Write (buf, string, offset, length) {
|
|
972
|
+
return asciiWrite(buf, string, offset, length);
|
|
976
973
|
}
|
|
977
974
|
|
|
978
|
-
function
|
|
979
|
-
|
|
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
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
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
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
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
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
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
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
function asciiSlice(buf, start, end) {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
function latin1Slice(buf, start, end) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
function hexSlice(buf, start, end) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
function utf16leSlice(buf, start, end) {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
Buffer.prototype.slice = function slice(start, end) {
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
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
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
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
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1288
|
+
Buffer.prototype.readUIntLE = function readUIntLE (
|
|
1289
|
+
offset,
|
|
1290
|
+
byteLength,
|
|
1291
|
+
noAssert,
|
|
1291
1292
|
) {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
Buffer.prototype.readUIntBE = function readUIntBE(
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
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
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
function checkInt(buf, value, offset, ext, max, min) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE(
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
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
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE(
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
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
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
function objectWriteUInt16(buf, value, offset, littleEndian) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
Buffer.prototype.writeUInt16LE = function writeUInt16LE(
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
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
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE(
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
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
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
function objectWriteUInt32(buf, value, offset, littleEndian) {
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
Buffer.prototype.writeUInt32LE = function writeUInt32LE(
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
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
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
Buffer.prototype.writeUInt32BE = function writeUInt32BE(
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
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
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
Buffer.prototype.writeIntLE = function writeIntLE(
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
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
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
Buffer.prototype.writeIntBE = function writeIntBE(
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
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
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1752
|
-
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1756
|
-
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE(
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
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
|
-
|
|
1780
|
-
}
|
|
1780
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1781
|
+
};
|
|
1781
1782
|
|
|
1782
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE(
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1783
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (
|
|
1784
|
+
value,
|
|
1785
|
+
offset,
|
|
1786
|
+
noAssert,
|
|
1786
1787
|
) {
|
|
1787
|
-
|
|
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
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
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
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
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
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
function stringtrim(str) {
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
function toHex(n) {
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
function utf8ToBytes(string, units) {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
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
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
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
|
-
|
|
2007
|
+
return bytes;
|
|
2007
2008
|
}
|
|
2008
2009
|
|
|
2009
|
-
function asciiToBytes(str) {
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
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
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2035
|
+
function base64ToBytes (str) {
|
|
2036
|
+
return base64toByteArray(base64clean(str));
|
|
2036
2037
|
}
|
|
2037
2038
|
|
|
2038
|
-
function blitBuffer(src, dst, offset, length) {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
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
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
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
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
function ieee754read(buffer, offset, isLE, mLen, nBytes) {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
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
|
-
|
|
2105
|
-
e = e - eBias
|
|
2135
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
2106
2136
|
}
|
|
2107
|
-
|
|
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
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
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
|
}
|