msgpackr 1.11.12 → 2.0.0
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/README.md +16 -0
- package/dist/index-no-eval.cjs +209 -245
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +209 -245
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +232 -1064
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +246 -1137
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +167 -186
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.js +5 -5
- package/iterators.js +28 -28
- package/node-index.js +12 -13
- package/pack.js +580 -611
- package/package.json +1 -1
- package/stream.js +31 -31
- package/unpack.js +612 -630
- package/struct.js +0 -815
package/dist/unpack-no-eval.cjs
CHANGED
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
C1.name = 'MessagePack 0xC1';
|
|
33
33
|
var sequentialMode = false;
|
|
34
34
|
var inlineObjectReadThreshold = 2;
|
|
35
|
-
var readStruct, onLoadedStructures, onSaveState;
|
|
36
35
|
var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
|
|
37
36
|
|
|
38
37
|
class Unpackr {
|
|
@@ -65,8 +64,8 @@
|
|
|
65
64
|
// re-entrant execution, save the state and restore it after we do this unpack
|
|
66
65
|
return saveState(() => {
|
|
67
66
|
clearSource();
|
|
68
|
-
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
|
|
69
|
-
})
|
|
67
|
+
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
|
|
68
|
+
});
|
|
70
69
|
}
|
|
71
70
|
if (!source.buffer && source.constructor === ArrayBuffer)
|
|
72
71
|
source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
|
|
@@ -92,14 +91,14 @@
|
|
|
92
91
|
// if it doesn't have a buffer, maybe it is the wrong type of object
|
|
93
92
|
src = null;
|
|
94
93
|
if (source instanceof Uint8Array)
|
|
95
|
-
throw error
|
|
96
|
-
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
|
|
94
|
+
throw error;
|
|
95
|
+
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
|
|
97
96
|
}
|
|
98
97
|
if (this instanceof Unpackr) {
|
|
99
98
|
currentUnpackr = this;
|
|
100
99
|
if (this.structures) {
|
|
101
100
|
currentStructures = this.structures;
|
|
102
|
-
return checkedRead(
|
|
101
|
+
return checkedRead();
|
|
103
102
|
} else if (!currentStructures || currentStructures.length > 0) {
|
|
104
103
|
currentStructures = [];
|
|
105
104
|
}
|
|
@@ -108,7 +107,7 @@
|
|
|
108
107
|
if (!currentStructures || currentStructures.length > 0)
|
|
109
108
|
currentStructures = [];
|
|
110
109
|
}
|
|
111
|
-
return checkedRead(
|
|
110
|
+
return checkedRead();
|
|
112
111
|
}
|
|
113
112
|
unpackMultiple(source, forEach) {
|
|
114
113
|
let values, lastPosition = 0;
|
|
@@ -121,7 +120,7 @@
|
|
|
121
120
|
while(position < size) {
|
|
122
121
|
lastPosition = position;
|
|
123
122
|
if (forEach(checkedRead(), lastPosition, position) === false) {
|
|
124
|
-
return
|
|
123
|
+
return;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
}
|
|
@@ -131,20 +130,18 @@
|
|
|
131
130
|
lastPosition = position;
|
|
132
131
|
values.push(checkedRead());
|
|
133
132
|
}
|
|
134
|
-
return values
|
|
133
|
+
return values;
|
|
135
134
|
}
|
|
136
135
|
} catch(error) {
|
|
137
136
|
error.lastPosition = lastPosition;
|
|
138
137
|
error.values = values;
|
|
139
|
-
throw error
|
|
138
|
+
throw error;
|
|
140
139
|
} finally {
|
|
141
140
|
sequentialMode = false;
|
|
142
141
|
clearSource();
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
_mergeStructures(loadedStructures, existingStructures) {
|
|
146
|
-
if (onLoadedStructures)
|
|
147
|
-
loadedStructures = onLoadedStructures.call(this, loadedStructures);
|
|
148
145
|
loadedStructures = loadedStructures || [];
|
|
149
146
|
if (Object.isFrozen(loadedStructures))
|
|
150
147
|
loadedStructures = loadedStructures.map(structure => structure.slice(0));
|
|
@@ -168,14 +165,14 @@
|
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
}
|
|
171
|
-
return this.structures = loadedStructures
|
|
168
|
+
return this.structures = loadedStructures;
|
|
172
169
|
}
|
|
173
170
|
decode(source, options) {
|
|
174
|
-
return this.unpack(source, options)
|
|
171
|
+
return this.unpack(source, options);
|
|
175
172
|
}
|
|
176
173
|
}
|
|
177
174
|
function getPosition() {
|
|
178
|
-
return position
|
|
175
|
+
return position;
|
|
179
176
|
}
|
|
180
177
|
function checkedRead(options) {
|
|
181
178
|
try {
|
|
@@ -184,15 +181,7 @@
|
|
|
184
181
|
if (sharedLength < currentStructures.length)
|
|
185
182
|
currentStructures.length = sharedLength;
|
|
186
183
|
}
|
|
187
|
-
let result;
|
|
188
|
-
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
189
|
-
result = readStruct(src, position, srcEnd, currentUnpackr);
|
|
190
|
-
src = null; // dispose of this so that recursive unpack calls don't save state
|
|
191
|
-
if (!(options && options.lazy) && result)
|
|
192
|
-
result = result.toJSON();
|
|
193
|
-
position = srcEnd;
|
|
194
|
-
} else
|
|
195
|
-
result = read();
|
|
184
|
+
let result = read();
|
|
196
185
|
if (bundledStrings) { // bundled strings to skip past
|
|
197
186
|
position = bundledStrings.postBundlePosition;
|
|
198
187
|
bundledStrings = null;
|
|
@@ -212,7 +201,7 @@
|
|
|
212
201
|
referenceMap = null;
|
|
213
202
|
} else if (position > srcEnd) {
|
|
214
203
|
// over read
|
|
215
|
-
throw new Error('Unexpected end of MessagePack data')
|
|
204
|
+
throw new Error('Unexpected end of MessagePack data');
|
|
216
205
|
} else if (!sequentialMode) {
|
|
217
206
|
let jsonView;
|
|
218
207
|
try {
|
|
@@ -220,10 +209,10 @@
|
|
|
220
209
|
} catch(error) {
|
|
221
210
|
jsonView = '(JSON view not available ' + error + ')';
|
|
222
211
|
}
|
|
223
|
-
throw new Error('Data read, but end of buffer not reached ' + jsonView)
|
|
212
|
+
throw new Error('Data read, but end of buffer not reached ' + jsonView);
|
|
224
213
|
}
|
|
225
214
|
// else more to read, but we are reading sequentially, so don't clear source yet
|
|
226
|
-
return result
|
|
215
|
+
return result;
|
|
227
216
|
} catch(error) {
|
|
228
217
|
if (currentStructures && currentStructures.restoreStructures)
|
|
229
218
|
restoreStructures();
|
|
@@ -231,7 +220,7 @@
|
|
|
231
220
|
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
|
|
232
221
|
error.incomplete = true;
|
|
233
222
|
}
|
|
234
|
-
throw error
|
|
223
|
+
throw error;
|
|
235
224
|
}
|
|
236
225
|
}
|
|
237
226
|
|
|
@@ -247,7 +236,7 @@
|
|
|
247
236
|
if (token < 0xa0) {
|
|
248
237
|
if (token < 0x80) {
|
|
249
238
|
if (token < 0x40)
|
|
250
|
-
return token
|
|
239
|
+
return token;
|
|
251
240
|
else {
|
|
252
241
|
let structure = currentStructures[token & 0x3f] ||
|
|
253
242
|
currentUnpackr.getStructures && loadStructures()[token & 0x3f];
|
|
@@ -255,9 +244,9 @@
|
|
|
255
244
|
if (!structure.read) {
|
|
256
245
|
structure.read = createStructureReader(structure, token & 0x3f);
|
|
257
246
|
}
|
|
258
|
-
return structure.read()
|
|
247
|
+
return structure.read();
|
|
259
248
|
} else
|
|
260
|
-
return token
|
|
249
|
+
return token;
|
|
261
250
|
}
|
|
262
251
|
} else if (token < 0x90) {
|
|
263
252
|
// map
|
|
@@ -270,13 +259,13 @@
|
|
|
270
259
|
key = '__proto_';
|
|
271
260
|
object[key] = read();
|
|
272
261
|
}
|
|
273
|
-
return object
|
|
262
|
+
return object;
|
|
274
263
|
} else {
|
|
275
264
|
let map = new Map();
|
|
276
265
|
for (let i = 0; i < token; i++) {
|
|
277
266
|
map.set(read(), read());
|
|
278
267
|
}
|
|
279
|
-
return map
|
|
268
|
+
return map;
|
|
280
269
|
}
|
|
281
270
|
} else {
|
|
282
271
|
token -= 0x90;
|
|
@@ -285,91 +274,91 @@
|
|
|
285
274
|
array[i] = read();
|
|
286
275
|
}
|
|
287
276
|
if (currentUnpackr.freezeData)
|
|
288
|
-
return Object.freeze(array)
|
|
289
|
-
return array
|
|
277
|
+
return Object.freeze(array);
|
|
278
|
+
return array;
|
|
290
279
|
}
|
|
291
280
|
} else if (token < 0xc0) {
|
|
292
281
|
// fixstr
|
|
293
282
|
let length = token - 0xa0;
|
|
294
283
|
if (srcStringEnd >= position) {
|
|
295
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
284
|
+
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
|
|
296
285
|
}
|
|
297
286
|
if (srcStringEnd == 0 && srcEnd < 140) {
|
|
298
287
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
299
288
|
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
300
289
|
if (string != null)
|
|
301
|
-
return string
|
|
290
|
+
return string;
|
|
302
291
|
}
|
|
303
|
-
return readFixedString(length)
|
|
292
|
+
return readFixedString(length);
|
|
304
293
|
} else {
|
|
305
294
|
let value;
|
|
306
295
|
switch (token) {
|
|
307
|
-
case 0xc0: return null
|
|
296
|
+
case 0xc0: return null;
|
|
308
297
|
case 0xc1:
|
|
309
298
|
if (bundledStrings) {
|
|
310
299
|
value = read(); // followed by the length of the string in characters (not bytes!)
|
|
311
300
|
if (value > 0)
|
|
312
|
-
return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
|
|
301
|
+
return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value);
|
|
313
302
|
else
|
|
314
|
-
return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
|
|
303
|
+
return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value);
|
|
315
304
|
}
|
|
316
305
|
return C1; // "never-used", return special object to denote that
|
|
317
|
-
case 0xc2: return false
|
|
318
|
-
case 0xc3: return true
|
|
306
|
+
case 0xc2: return false;
|
|
307
|
+
case 0xc3: return true;
|
|
319
308
|
case 0xc4:
|
|
320
309
|
// bin 8
|
|
321
310
|
value = src[position++];
|
|
322
311
|
if (value === undefined)
|
|
323
|
-
throw new Error('Unexpected end of buffer')
|
|
324
|
-
return readBin(value)
|
|
312
|
+
throw new Error('Unexpected end of buffer');
|
|
313
|
+
return readBin(value);
|
|
325
314
|
case 0xc5:
|
|
326
315
|
// bin 16
|
|
327
316
|
value = dataView.getUint16(position);
|
|
328
317
|
position += 2;
|
|
329
|
-
return readBin(value)
|
|
318
|
+
return readBin(value);
|
|
330
319
|
case 0xc6:
|
|
331
320
|
// bin 32
|
|
332
321
|
value = dataView.getUint32(position);
|
|
333
322
|
position += 4;
|
|
334
|
-
return readBin(value)
|
|
323
|
+
return readBin(value);
|
|
335
324
|
case 0xc7:
|
|
336
325
|
// ext 8
|
|
337
|
-
return readExt(src[position++])
|
|
326
|
+
return readExt(src[position++]);
|
|
338
327
|
case 0xc8:
|
|
339
328
|
// ext 16
|
|
340
329
|
value = dataView.getUint16(position);
|
|
341
330
|
position += 2;
|
|
342
|
-
return readExt(value)
|
|
331
|
+
return readExt(value);
|
|
343
332
|
case 0xc9:
|
|
344
333
|
// ext 32
|
|
345
334
|
value = dataView.getUint32(position);
|
|
346
335
|
position += 4;
|
|
347
|
-
return readExt(value)
|
|
336
|
+
return readExt(value);
|
|
348
337
|
case 0xca:
|
|
349
338
|
value = dataView.getFloat32(position);
|
|
350
339
|
if (currentUnpackr.useFloat32 > 2) {
|
|
351
340
|
// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
352
341
|
let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
|
|
353
342
|
position += 4;
|
|
354
|
-
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
343
|
+
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
355
344
|
}
|
|
356
345
|
position += 4;
|
|
357
|
-
return value
|
|
346
|
+
return value;
|
|
358
347
|
case 0xcb:
|
|
359
348
|
value = dataView.getFloat64(position);
|
|
360
349
|
position += 8;
|
|
361
|
-
return value
|
|
350
|
+
return value;
|
|
362
351
|
// uint handlers
|
|
363
352
|
case 0xcc:
|
|
364
|
-
return src[position++]
|
|
353
|
+
return src[position++];
|
|
365
354
|
case 0xcd:
|
|
366
355
|
value = dataView.getUint16(position);
|
|
367
356
|
position += 2;
|
|
368
|
-
return value
|
|
357
|
+
return value;
|
|
369
358
|
case 0xce:
|
|
370
359
|
value = dataView.getUint32(position);
|
|
371
360
|
position += 4;
|
|
372
|
-
return value
|
|
361
|
+
return value;
|
|
373
362
|
case 0xcf:
|
|
374
363
|
if (currentUnpackr.int64AsType === 'number') {
|
|
375
364
|
value = dataView.getUint32(position) * 0x100000000;
|
|
@@ -382,19 +371,19 @@
|
|
|
382
371
|
} else
|
|
383
372
|
value = dataView.getBigUint64(position);
|
|
384
373
|
position += 8;
|
|
385
|
-
return value
|
|
374
|
+
return value;
|
|
386
375
|
|
|
387
376
|
// int handlers
|
|
388
377
|
case 0xd0:
|
|
389
|
-
return dataView.getInt8(position++)
|
|
378
|
+
return dataView.getInt8(position++);
|
|
390
379
|
case 0xd1:
|
|
391
380
|
value = dataView.getInt16(position);
|
|
392
381
|
position += 2;
|
|
393
|
-
return value
|
|
382
|
+
return value;
|
|
394
383
|
case 0xd2:
|
|
395
384
|
value = dataView.getInt32(position);
|
|
396
385
|
position += 4;
|
|
397
|
-
return value
|
|
386
|
+
return value;
|
|
398
387
|
case 0xd3:
|
|
399
388
|
if (currentUnpackr.int64AsType === 'number') {
|
|
400
389
|
value = dataView.getInt32(position) * 0x100000000;
|
|
@@ -407,96 +396,96 @@
|
|
|
407
396
|
} else
|
|
408
397
|
value = dataView.getBigInt64(position);
|
|
409
398
|
position += 8;
|
|
410
|
-
return value
|
|
399
|
+
return value;
|
|
411
400
|
|
|
412
401
|
case 0xd4:
|
|
413
402
|
// fixext 1
|
|
414
403
|
value = src[position++];
|
|
415
404
|
if (value == 0x72) {
|
|
416
|
-
return recordDefinition(src[position++] & 0x3f)
|
|
405
|
+
return recordDefinition(src[position++] & 0x3f);
|
|
417
406
|
} else {
|
|
418
407
|
let extension = currentExtensions[value];
|
|
419
408
|
if (extension) {
|
|
420
409
|
if (extension.read) {
|
|
421
410
|
position++; // skip filler byte
|
|
422
|
-
return extension.read(read())
|
|
411
|
+
return extension.read(read());
|
|
423
412
|
} else if (extension.noBuffer) {
|
|
424
413
|
position++; // skip filler byte
|
|
425
|
-
return extension()
|
|
414
|
+
return extension();
|
|
426
415
|
} else
|
|
427
|
-
return extension(src.subarray(position, ++position))
|
|
416
|
+
return extension(src.subarray(position, ++position));
|
|
428
417
|
} else
|
|
429
|
-
throw new Error('Unknown extension ' + value)
|
|
418
|
+
throw new Error('Unknown extension ' + value);
|
|
430
419
|
}
|
|
431
420
|
case 0xd5:
|
|
432
421
|
// fixext 2
|
|
433
422
|
value = src[position];
|
|
434
423
|
if (value == 0x72) {
|
|
435
424
|
position++;
|
|
436
|
-
return recordDefinition(src[position++] & 0x3f, src[position++])
|
|
425
|
+
return recordDefinition(src[position++] & 0x3f, src[position++]);
|
|
437
426
|
} else
|
|
438
|
-
return readExt(2)
|
|
427
|
+
return readExt(2);
|
|
439
428
|
case 0xd6:
|
|
440
429
|
// fixext 4
|
|
441
|
-
return readExt(4)
|
|
430
|
+
return readExt(4);
|
|
442
431
|
case 0xd7:
|
|
443
432
|
// fixext 8
|
|
444
|
-
return readExt(8)
|
|
433
|
+
return readExt(8);
|
|
445
434
|
case 0xd8:
|
|
446
435
|
// fixext 16
|
|
447
|
-
return readExt(16)
|
|
436
|
+
return readExt(16);
|
|
448
437
|
case 0xd9:
|
|
449
438
|
// str 8
|
|
450
439
|
value = src[position++];
|
|
451
440
|
if (srcStringEnd >= position) {
|
|
452
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
441
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
453
442
|
}
|
|
454
|
-
return readString8(value)
|
|
443
|
+
return readString8(value);
|
|
455
444
|
case 0xda:
|
|
456
445
|
// str 16
|
|
457
446
|
value = dataView.getUint16(position);
|
|
458
447
|
position += 2;
|
|
459
448
|
if (srcStringEnd >= position) {
|
|
460
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
449
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
461
450
|
}
|
|
462
|
-
return readString16(value)
|
|
451
|
+
return readString16(value);
|
|
463
452
|
case 0xdb:
|
|
464
453
|
// str 32
|
|
465
454
|
value = dataView.getUint32(position);
|
|
466
455
|
position += 4;
|
|
467
456
|
if (srcStringEnd >= position) {
|
|
468
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
457
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
469
458
|
}
|
|
470
|
-
return readString32(value)
|
|
459
|
+
return readString32(value);
|
|
471
460
|
case 0xdc:
|
|
472
461
|
// array 16
|
|
473
462
|
value = dataView.getUint16(position);
|
|
474
463
|
position += 2;
|
|
475
|
-
return readArray(value)
|
|
464
|
+
return readArray(value);
|
|
476
465
|
case 0xdd:
|
|
477
466
|
// array 32
|
|
478
467
|
value = dataView.getUint32(position);
|
|
479
468
|
position += 4;
|
|
480
|
-
return readArray(value)
|
|
469
|
+
return readArray(value);
|
|
481
470
|
case 0xde:
|
|
482
471
|
// map 16
|
|
483
472
|
value = dataView.getUint16(position);
|
|
484
473
|
position += 2;
|
|
485
|
-
return readMap(value)
|
|
474
|
+
return readMap(value);
|
|
486
475
|
case 0xdf:
|
|
487
476
|
// map 32
|
|
488
477
|
value = dataView.getUint32(position);
|
|
489
478
|
position += 4;
|
|
490
|
-
return readMap(value)
|
|
479
|
+
return readMap(value);
|
|
491
480
|
default: // negative int
|
|
492
481
|
if (token >= 0xe0)
|
|
493
|
-
return token - 0x100
|
|
482
|
+
return token - 0x100;
|
|
494
483
|
if (token === undefined) {
|
|
495
484
|
let error = new Error('Unexpected end of MessagePack data');
|
|
496
485
|
error.incomplete = true;
|
|
497
|
-
throw error
|
|
486
|
+
throw error;
|
|
498
487
|
}
|
|
499
|
-
throw new Error('Unknown MessagePack token ' + token)
|
|
488
|
+
throw new Error('Unknown MessagePack token ' + token);
|
|
500
489
|
|
|
501
490
|
}
|
|
502
491
|
}
|
|
@@ -517,7 +506,7 @@
|
|
|
517
506
|
}
|
|
518
507
|
if (structure.highByte === 0)
|
|
519
508
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
520
|
-
return optimizedReadObject() // second byte is already read, if there is one so immediately read object
|
|
509
|
+
return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
|
|
521
510
|
}
|
|
522
511
|
let object = {};
|
|
523
512
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
@@ -528,38 +517,38 @@
|
|
|
528
517
|
}
|
|
529
518
|
if (currentUnpackr.freezeData)
|
|
530
519
|
return Object.freeze(object);
|
|
531
|
-
return object
|
|
520
|
+
return object;
|
|
532
521
|
}
|
|
533
522
|
readObject.count = 0;
|
|
534
523
|
if (structure.highByte === 0) {
|
|
535
|
-
return createSecondByteReader(firstId, readObject)
|
|
524
|
+
return createSecondByteReader(firstId, readObject);
|
|
536
525
|
}
|
|
537
|
-
return readObject
|
|
526
|
+
return readObject;
|
|
538
527
|
}
|
|
539
528
|
|
|
540
529
|
const createSecondByteReader = (firstId, read0) => {
|
|
541
530
|
return function() {
|
|
542
531
|
let highByte = src[position++];
|
|
543
532
|
if (highByte === 0)
|
|
544
|
-
return read0()
|
|
533
|
+
return read0();
|
|
545
534
|
let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
|
|
546
535
|
let structure = currentStructures[id] || loadStructures()[id];
|
|
547
536
|
if (!structure) {
|
|
548
|
-
throw new Error('Record id is not defined for ' + id)
|
|
537
|
+
throw new Error('Record id is not defined for ' + id);
|
|
549
538
|
}
|
|
550
539
|
if (!structure.read)
|
|
551
540
|
structure.read = createStructureReader(structure, firstId);
|
|
552
|
-
return structure.read()
|
|
553
|
-
}
|
|
541
|
+
return structure.read();
|
|
542
|
+
};
|
|
554
543
|
};
|
|
555
544
|
|
|
556
545
|
function loadStructures() {
|
|
557
546
|
let loadedStructures = saveState(() => {
|
|
558
547
|
// save the state in case getStructures modifies our buffer
|
|
559
548
|
src = null;
|
|
560
|
-
return currentUnpackr.getStructures()
|
|
549
|
+
return currentUnpackr.getStructures();
|
|
561
550
|
});
|
|
562
|
-
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
|
|
551
|
+
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
|
|
563
552
|
}
|
|
564
553
|
|
|
565
554
|
var readFixedString = readStringJS;
|
|
@@ -579,7 +568,7 @@
|
|
|
579
568
|
let string = strings[stringPosition++];
|
|
580
569
|
if (string == null) {
|
|
581
570
|
if (bundledStrings)
|
|
582
|
-
return readStringJS(length)
|
|
571
|
+
return readStringJS(length);
|
|
583
572
|
let byteOffset = src.byteOffset;
|
|
584
573
|
let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
|
|
585
574
|
if (typeof extraction == 'string') {
|
|
@@ -591,30 +580,30 @@
|
|
|
591
580
|
srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
|
|
592
581
|
string = strings[0];
|
|
593
582
|
if (string === undefined)
|
|
594
|
-
throw new Error('Unexpected end of buffer')
|
|
583
|
+
throw new Error('Unexpected end of buffer');
|
|
595
584
|
}
|
|
596
585
|
}
|
|
597
586
|
let srcStringLength = string.length;
|
|
598
587
|
if (srcStringLength <= length) {
|
|
599
588
|
position += length;
|
|
600
|
-
return string
|
|
589
|
+
return string;
|
|
601
590
|
}
|
|
602
591
|
srcString = string;
|
|
603
592
|
srcStringStart = position;
|
|
604
593
|
srcStringEnd = position + srcStringLength;
|
|
605
594
|
position += length;
|
|
606
|
-
return string.slice(0, length) // we know we just want the beginning
|
|
607
|
-
}
|
|
595
|
+
return string.slice(0, length); // we know we just want the beginning
|
|
596
|
+
};
|
|
608
597
|
}
|
|
609
598
|
}
|
|
610
599
|
function readStringJS(length) {
|
|
611
600
|
let result;
|
|
612
601
|
if (length < 16) {
|
|
613
602
|
if (result = shortStringInJS(length))
|
|
614
|
-
return result
|
|
603
|
+
return result;
|
|
615
604
|
}
|
|
616
605
|
if (length > 64 && decoder)
|
|
617
|
-
return decoder.decode(src.subarray(position, position += length))
|
|
606
|
+
return decoder.decode(src.subarray(position, position += length));
|
|
618
607
|
const end = position + length;
|
|
619
608
|
const units = [];
|
|
620
609
|
result = '';
|
|
@@ -677,7 +666,7 @@
|
|
|
677
666
|
result += fromCharCode.apply(String, units);
|
|
678
667
|
}
|
|
679
668
|
|
|
680
|
-
return result
|
|
669
|
+
return result;
|
|
681
670
|
}
|
|
682
671
|
function readString(source, start, length) {
|
|
683
672
|
let existingSrc = src;
|
|
@@ -696,8 +685,8 @@
|
|
|
696
685
|
array[i] = read();
|
|
697
686
|
}
|
|
698
687
|
if (currentUnpackr.freezeData)
|
|
699
|
-
return Object.freeze(array)
|
|
700
|
-
return array
|
|
688
|
+
return Object.freeze(array);
|
|
689
|
+
return array;
|
|
701
690
|
}
|
|
702
691
|
|
|
703
692
|
function readMap(length) {
|
|
@@ -709,13 +698,13 @@
|
|
|
709
698
|
key = '__proto_';
|
|
710
699
|
object[key] = read();
|
|
711
700
|
}
|
|
712
|
-
return object
|
|
701
|
+
return object;
|
|
713
702
|
} else {
|
|
714
703
|
let map = new Map();
|
|
715
704
|
for (let i = 0; i < length; i++) {
|
|
716
705
|
map.set(read(), read());
|
|
717
706
|
}
|
|
718
|
-
return map
|
|
707
|
+
return map;
|
|
719
708
|
}
|
|
720
709
|
}
|
|
721
710
|
|
|
@@ -727,40 +716,40 @@
|
|
|
727
716
|
const byte = src[position++];
|
|
728
717
|
if ((byte & 0x80) > 0) {
|
|
729
718
|
position = start;
|
|
730
|
-
return
|
|
719
|
+
return;
|
|
731
720
|
}
|
|
732
721
|
bytes[i] = byte;
|
|
733
722
|
}
|
|
734
|
-
return fromCharCode.apply(String, bytes)
|
|
723
|
+
return fromCharCode.apply(String, bytes);
|
|
735
724
|
}
|
|
736
725
|
function shortStringInJS(length) {
|
|
737
726
|
if (length < 4) {
|
|
738
727
|
if (length < 2) {
|
|
739
728
|
if (length === 0)
|
|
740
|
-
return ''
|
|
729
|
+
return '';
|
|
741
730
|
else {
|
|
742
731
|
let a = src[position++];
|
|
743
732
|
if ((a & 0x80) > 1) {
|
|
744
733
|
position -= 1;
|
|
745
|
-
return
|
|
734
|
+
return;
|
|
746
735
|
}
|
|
747
|
-
return fromCharCode(a)
|
|
736
|
+
return fromCharCode(a);
|
|
748
737
|
}
|
|
749
738
|
} else {
|
|
750
739
|
let a = src[position++];
|
|
751
740
|
let b = src[position++];
|
|
752
741
|
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
|
|
753
742
|
position -= 2;
|
|
754
|
-
return
|
|
743
|
+
return;
|
|
755
744
|
}
|
|
756
745
|
if (length < 3)
|
|
757
|
-
return fromCharCode(a, b)
|
|
746
|
+
return fromCharCode(a, b);
|
|
758
747
|
let c = src[position++];
|
|
759
748
|
if ((c & 0x80) > 0) {
|
|
760
749
|
position -= 3;
|
|
761
|
-
return
|
|
750
|
+
return;
|
|
762
751
|
}
|
|
763
|
-
return fromCharCode(a, b, c)
|
|
752
|
+
return fromCharCode(a, b, c);
|
|
764
753
|
}
|
|
765
754
|
} else {
|
|
766
755
|
let a = src[position++];
|
|
@@ -769,34 +758,34 @@
|
|
|
769
758
|
let d = src[position++];
|
|
770
759
|
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
|
|
771
760
|
position -= 4;
|
|
772
|
-
return
|
|
761
|
+
return;
|
|
773
762
|
}
|
|
774
763
|
if (length < 6) {
|
|
775
764
|
if (length === 4)
|
|
776
|
-
return fromCharCode(a, b, c, d)
|
|
765
|
+
return fromCharCode(a, b, c, d);
|
|
777
766
|
else {
|
|
778
767
|
let e = src[position++];
|
|
779
768
|
if ((e & 0x80) > 0) {
|
|
780
769
|
position -= 5;
|
|
781
|
-
return
|
|
770
|
+
return;
|
|
782
771
|
}
|
|
783
|
-
return fromCharCode(a, b, c, d, e)
|
|
772
|
+
return fromCharCode(a, b, c, d, e);
|
|
784
773
|
}
|
|
785
774
|
} else if (length < 8) {
|
|
786
775
|
let e = src[position++];
|
|
787
776
|
let f = src[position++];
|
|
788
777
|
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
|
|
789
778
|
position -= 6;
|
|
790
|
-
return
|
|
779
|
+
return;
|
|
791
780
|
}
|
|
792
781
|
if (length < 7)
|
|
793
|
-
return fromCharCode(a, b, c, d, e, f)
|
|
782
|
+
return fromCharCode(a, b, c, d, e, f);
|
|
794
783
|
let g = src[position++];
|
|
795
784
|
if ((g & 0x80) > 0) {
|
|
796
785
|
position -= 7;
|
|
797
|
-
return
|
|
786
|
+
return;
|
|
798
787
|
}
|
|
799
|
-
return fromCharCode(a, b, c, d, e, f, g)
|
|
788
|
+
return fromCharCode(a, b, c, d, e, f, g);
|
|
800
789
|
} else {
|
|
801
790
|
let e = src[position++];
|
|
802
791
|
let f = src[position++];
|
|
@@ -804,34 +793,34 @@
|
|
|
804
793
|
let h = src[position++];
|
|
805
794
|
if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
|
|
806
795
|
position -= 8;
|
|
807
|
-
return
|
|
796
|
+
return;
|
|
808
797
|
}
|
|
809
798
|
if (length < 10) {
|
|
810
799
|
if (length === 8)
|
|
811
|
-
return fromCharCode(a, b, c, d, e, f, g, h)
|
|
800
|
+
return fromCharCode(a, b, c, d, e, f, g, h);
|
|
812
801
|
else {
|
|
813
802
|
let i = src[position++];
|
|
814
803
|
if ((i & 0x80) > 0) {
|
|
815
804
|
position -= 9;
|
|
816
|
-
return
|
|
805
|
+
return;
|
|
817
806
|
}
|
|
818
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i)
|
|
807
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i);
|
|
819
808
|
}
|
|
820
809
|
} else if (length < 12) {
|
|
821
810
|
let i = src[position++];
|
|
822
811
|
let j = src[position++];
|
|
823
812
|
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
|
|
824
813
|
position -= 10;
|
|
825
|
-
return
|
|
814
|
+
return;
|
|
826
815
|
}
|
|
827
816
|
if (length < 11)
|
|
828
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j)
|
|
817
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j);
|
|
829
818
|
let k = src[position++];
|
|
830
819
|
if ((k & 0x80) > 0) {
|
|
831
820
|
position -= 11;
|
|
832
|
-
return
|
|
821
|
+
return;
|
|
833
822
|
}
|
|
834
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
|
|
823
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
|
|
835
824
|
} else {
|
|
836
825
|
let i = src[position++];
|
|
837
826
|
let j = src[position++];
|
|
@@ -839,34 +828,34 @@
|
|
|
839
828
|
let l = src[position++];
|
|
840
829
|
if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
|
|
841
830
|
position -= 12;
|
|
842
|
-
return
|
|
831
|
+
return;
|
|
843
832
|
}
|
|
844
833
|
if (length < 14) {
|
|
845
834
|
if (length === 12)
|
|
846
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
|
|
835
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
|
|
847
836
|
else {
|
|
848
837
|
let m = src[position++];
|
|
849
838
|
if ((m & 0x80) > 0) {
|
|
850
839
|
position -= 13;
|
|
851
|
-
return
|
|
840
|
+
return;
|
|
852
841
|
}
|
|
853
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
|
|
842
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
|
|
854
843
|
}
|
|
855
844
|
} else {
|
|
856
845
|
let m = src[position++];
|
|
857
846
|
let n = src[position++];
|
|
858
847
|
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
|
|
859
848
|
position -= 14;
|
|
860
|
-
return
|
|
849
|
+
return;
|
|
861
850
|
}
|
|
862
851
|
if (length < 15)
|
|
863
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
|
|
852
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
|
|
864
853
|
let o = src[position++];
|
|
865
854
|
if ((o & 0x80) > 0) {
|
|
866
855
|
position -= 15;
|
|
867
|
-
return
|
|
856
|
+
return;
|
|
868
857
|
}
|
|
869
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
|
|
858
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
|
|
870
859
|
}
|
|
871
860
|
}
|
|
872
861
|
}
|
|
@@ -884,22 +873,22 @@
|
|
|
884
873
|
case 0xd9:
|
|
885
874
|
// str 8
|
|
886
875
|
length = src[position++];
|
|
887
|
-
break
|
|
876
|
+
break;
|
|
888
877
|
case 0xda:
|
|
889
878
|
// str 16
|
|
890
879
|
length = dataView.getUint16(position);
|
|
891
880
|
position += 2;
|
|
892
|
-
break
|
|
881
|
+
break;
|
|
893
882
|
case 0xdb:
|
|
894
883
|
// str 32
|
|
895
884
|
length = dataView.getUint32(position);
|
|
896
885
|
position += 4;
|
|
897
|
-
break
|
|
886
|
+
break;
|
|
898
887
|
default:
|
|
899
|
-
throw new Error('Expected string')
|
|
888
|
+
throw new Error('Expected string');
|
|
900
889
|
}
|
|
901
890
|
}
|
|
902
|
-
return readStringJS(length)
|
|
891
|
+
return readStringJS(length);
|
|
903
892
|
}
|
|
904
893
|
|
|
905
894
|
|
|
@@ -907,7 +896,7 @@
|
|
|
907
896
|
return currentUnpackr.copyBuffers ?
|
|
908
897
|
// specifically use the copying slice (not the node one)
|
|
909
898
|
Uint8Array.prototype.slice.call(src, position, position += length) :
|
|
910
|
-
src.subarray(position, position += length)
|
|
899
|
+
src.subarray(position, position += length);
|
|
911
900
|
}
|
|
912
901
|
function readExt(length) {
|
|
913
902
|
let type = src[position++];
|
|
@@ -920,10 +909,10 @@
|
|
|
920
909
|
} finally {
|
|
921
910
|
position = end;
|
|
922
911
|
}
|
|
923
|
-
})
|
|
912
|
+
});
|
|
924
913
|
}
|
|
925
914
|
else
|
|
926
|
-
throw new Error('Unknown extension type ' + type)
|
|
915
|
+
throw new Error('Unknown extension type ' + type);
|
|
927
916
|
}
|
|
928
917
|
|
|
929
918
|
var keyCache = new Array(4096);
|
|
@@ -933,12 +922,12 @@
|
|
|
933
922
|
// fixstr, potentially use key cache
|
|
934
923
|
length = length - 0xa0;
|
|
935
924
|
if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
|
|
936
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
925
|
+
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
|
|
937
926
|
else if (!(srcStringEnd == 0 && srcEnd < 180))
|
|
938
|
-
return readFixedString(length)
|
|
927
|
+
return readFixedString(length);
|
|
939
928
|
} else { // not cacheable, go back and do a standard read
|
|
940
929
|
position--;
|
|
941
|
-
return asSafeString(read())
|
|
930
|
+
return asSafeString(read());
|
|
942
931
|
}
|
|
943
932
|
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
|
|
944
933
|
let entry = keyCache[key];
|
|
@@ -951,7 +940,7 @@
|
|
|
951
940
|
chunk = dataView.getUint32(checkPosition);
|
|
952
941
|
if (chunk != entry[i++]) {
|
|
953
942
|
checkPosition = 0x70000000;
|
|
954
|
-
break
|
|
943
|
+
break;
|
|
955
944
|
}
|
|
956
945
|
checkPosition += 4;
|
|
957
946
|
}
|
|
@@ -960,12 +949,12 @@
|
|
|
960
949
|
chunk = src[checkPosition++];
|
|
961
950
|
if (chunk != entry[i++]) {
|
|
962
951
|
checkPosition = 0x70000000;
|
|
963
|
-
break
|
|
952
|
+
break;
|
|
964
953
|
}
|
|
965
954
|
}
|
|
966
955
|
if (checkPosition === end) {
|
|
967
956
|
position = checkPosition;
|
|
968
|
-
return entry.string
|
|
957
|
+
return entry.string;
|
|
969
958
|
}
|
|
970
959
|
end -= 3;
|
|
971
960
|
checkPosition = position;
|
|
@@ -986,8 +975,8 @@
|
|
|
986
975
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
987
976
|
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
988
977
|
if (string != null)
|
|
989
|
-
return entry.string = string
|
|
990
|
-
return entry.string = readFixedString(length)
|
|
978
|
+
return entry.string = string;
|
|
979
|
+
return entry.string = readFixedString(length);
|
|
991
980
|
}
|
|
992
981
|
|
|
993
982
|
function asSafeString(property) {
|
|
@@ -1018,7 +1007,7 @@
|
|
|
1018
1007
|
}
|
|
1019
1008
|
currentStructures[id] = structure;
|
|
1020
1009
|
structure.read = createStructureReader(structure, firstByte);
|
|
1021
|
-
return structure.read()
|
|
1010
|
+
return structure.read();
|
|
1022
1011
|
};
|
|
1023
1012
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
1024
1013
|
currentExtensions[0].noBuffer = true;
|
|
@@ -1040,17 +1029,17 @@
|
|
|
1040
1029
|
out <<= BigInt(64);
|
|
1041
1030
|
out |= view.getBigUint64(i);
|
|
1042
1031
|
}
|
|
1043
|
-
return out
|
|
1032
|
+
return out;
|
|
1044
1033
|
}
|
|
1045
1034
|
// if (length === 8) return view.getBigUint64(start)
|
|
1046
1035
|
let middle = start + (length >> 4 << 3);
|
|
1047
1036
|
let left = decode(start, middle);
|
|
1048
1037
|
let right = decode(middle, end);
|
|
1049
|
-
return (left << BigInt((end - middle) * 8)) | right
|
|
1038
|
+
return (left << BigInt((end - middle) * 8)) | right;
|
|
1050
1039
|
};
|
|
1051
1040
|
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
|
|
1052
1041
|
}
|
|
1053
|
-
return head
|
|
1042
|
+
return head;
|
|
1054
1043
|
};
|
|
1055
1044
|
|
|
1056
1045
|
let errors = {
|
|
@@ -1061,14 +1050,14 @@
|
|
|
1061
1050
|
if (!errors[data[0]]) {
|
|
1062
1051
|
let error = Error(data[1], { cause: data[2] });
|
|
1063
1052
|
error.name = data[0];
|
|
1064
|
-
return error
|
|
1053
|
+
return error;
|
|
1065
1054
|
}
|
|
1066
|
-
return errors[data[0]](data[1], { cause: data[2] })
|
|
1055
|
+
return errors[data[0]](data[1], { cause: data[2] });
|
|
1067
1056
|
};
|
|
1068
1057
|
|
|
1069
1058
|
currentExtensions[0x69] = (data) => {
|
|
1070
1059
|
// id extension (for structured clones)
|
|
1071
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1060
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1072
1061
|
let id = dataView.getUint32(position - 4);
|
|
1073
1062
|
if (!referenceMap)
|
|
1074
1063
|
referenceMap = new Map();
|
|
@@ -1089,7 +1078,7 @@
|
|
|
1089
1078
|
let targetProperties = read(); // read the next value as the target object to id
|
|
1090
1079
|
if (!refEntry.used) {
|
|
1091
1080
|
// no cycle, can just use the returned read object
|
|
1092
|
-
return refEntry.target = targetProperties // replace the placeholder with the real one
|
|
1081
|
+
return refEntry.target = targetProperties; // replace the placeholder with the real one
|
|
1093
1082
|
} else {
|
|
1094
1083
|
// there is a cycle, so we have to assign properties to original target
|
|
1095
1084
|
Object.assign(target, targetProperties);
|
|
@@ -1100,16 +1089,16 @@
|
|
|
1100
1089
|
for (let [k, v] of targetProperties.entries()) target.set(k, v);
|
|
1101
1090
|
if (target instanceof Set)
|
|
1102
1091
|
for (let i of Array.from(targetProperties)) target.add(i);
|
|
1103
|
-
return target
|
|
1092
|
+
return target;
|
|
1104
1093
|
};
|
|
1105
1094
|
|
|
1106
1095
|
currentExtensions[0x70] = (data) => {
|
|
1107
1096
|
// pointer extension (for structured clones)
|
|
1108
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1097
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1109
1098
|
let id = dataView.getUint32(position - 4);
|
|
1110
1099
|
let refEntry = referenceMap.get(id);
|
|
1111
1100
|
refEntry.used = true;
|
|
1112
|
-
return refEntry.target
|
|
1101
|
+
return refEntry.target;
|
|
1113
1102
|
};
|
|
1114
1103
|
|
|
1115
1104
|
currentExtensions[0x73] = () => new Set(read());
|
|
@@ -1124,15 +1113,15 @@
|
|
|
1124
1113
|
|
|
1125
1114
|
let typedArrayName = typedArrays[typeCode];
|
|
1126
1115
|
if (!typedArrayName) {
|
|
1127
|
-
if (typeCode === 16) return buffer
|
|
1128
|
-
if (typeCode === 17) return new DataView(buffer)
|
|
1129
|
-
throw new Error('Could not find typed array for code ' + typeCode)
|
|
1116
|
+
if (typeCode === 16) return buffer;
|
|
1117
|
+
if (typeCode === 17) return new DataView(buffer);
|
|
1118
|
+
throw new Error('Could not find typed array for code ' + typeCode);
|
|
1130
1119
|
}
|
|
1131
|
-
return new glbl[typedArrayName](buffer)
|
|
1120
|
+
return new glbl[typedArrayName](buffer);
|
|
1132
1121
|
};
|
|
1133
1122
|
currentExtensions[0x78] = () => {
|
|
1134
1123
|
let data = read();
|
|
1135
|
-
return new RegExp(data[0], data[1])
|
|
1124
|
+
return new RegExp(data[0], data[1]);
|
|
1136
1125
|
};
|
|
1137
1126
|
const TEMP_BUNDLE = [];
|
|
1138
1127
|
currentExtensions[0x62] = (data) => {
|
|
@@ -1145,30 +1134,28 @@
|
|
|
1145
1134
|
bundledStrings.position1 = 0;
|
|
1146
1135
|
bundledStrings.postBundlePosition = position;
|
|
1147
1136
|
position = dataPosition;
|
|
1148
|
-
return read()
|
|
1137
|
+
return read();
|
|
1149
1138
|
};
|
|
1150
1139
|
|
|
1151
1140
|
currentExtensions[0xff] = (data) => {
|
|
1152
1141
|
// 32-bit date extension
|
|
1153
1142
|
if (data.length == 4)
|
|
1154
|
-
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
|
|
1143
|
+
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
|
|
1155
1144
|
else if (data.length == 8)
|
|
1156
1145
|
return new Date(
|
|
1157
1146
|
((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
|
|
1158
|
-
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
|
|
1147
|
+
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
|
|
1159
1148
|
else if (data.length == 12)
|
|
1160
1149
|
return new Date(
|
|
1161
1150
|
((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
|
|
1162
|
-
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
|
|
1151
|
+
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
|
|
1163
1152
|
else
|
|
1164
|
-
return new Date('invalid')
|
|
1153
|
+
return new Date('invalid');
|
|
1165
1154
|
};
|
|
1166
1155
|
// registration of bulk record definition?
|
|
1167
1156
|
// currentExtensions[0x52] = () =>
|
|
1168
1157
|
|
|
1169
1158
|
function saveState(callback) {
|
|
1170
|
-
if (onSaveState)
|
|
1171
|
-
onSaveState();
|
|
1172
1159
|
let savedSrcEnd = srcEnd;
|
|
1173
1160
|
let savedPosition = position;
|
|
1174
1161
|
let savedStringPosition = stringPosition;
|
|
@@ -1201,7 +1188,7 @@
|
|
|
1201
1188
|
currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
|
|
1202
1189
|
currentUnpackr = savedPackr;
|
|
1203
1190
|
dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
1204
|
-
return value
|
|
1191
|
+
return value;
|
|
1205
1192
|
}
|
|
1206
1193
|
function clearSource() {
|
|
1207
1194
|
src = null;
|
|
@@ -1236,12 +1223,7 @@
|
|
|
1236
1223
|
function roundFloat32(float32Number) {
|
|
1237
1224
|
f32Array[0] = float32Number;
|
|
1238
1225
|
let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
|
|
1239
|
-
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
1240
|
-
}
|
|
1241
|
-
function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
|
|
1242
|
-
readStruct = updatedReadStruct;
|
|
1243
|
-
onLoadedStructures = loadedStructs;
|
|
1244
|
-
onSaveState = saveState;
|
|
1226
|
+
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
1245
1227
|
}
|
|
1246
1228
|
|
|
1247
1229
|
exports.C1 = C1;
|
|
@@ -1260,7 +1242,6 @@
|
|
|
1260
1242
|
exports.readString = readString;
|
|
1261
1243
|
exports.roundFloat32 = roundFloat32;
|
|
1262
1244
|
exports.setExtractor = setExtractor;
|
|
1263
|
-
exports.setReadStruct = setReadStruct;
|
|
1264
1245
|
exports.typedArrays = typedArrays;
|
|
1265
1246
|
exports.unpack = unpack;
|
|
1266
1247
|
exports.unpackMultiple = unpackMultiple;
|