msgpackr 1.7.2 → 1.8.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 +4 -1
- package/dist/index-no-eval.js +2164 -0
- package/dist/index-no-eval.js.map +1 -0
- package/dist/index-no-eval.min.js +2 -0
- package/dist/index-no-eval.min.js.map +1 -0
- package/dist/index.js +389 -370
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -84
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +420 -412
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +670 -498
- package/dist/test.js.map +1 -1
- package/index.d.ts +2 -0
- package/pack.js +4 -4
- package/package.json +7 -6
- package/rollup.config.js +32 -5
- package/struct.js +3 -3
- package/unpack.js +15 -4
package/dist/node.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var stream = require('stream');
|
|
6
4
|
var module$1 = require('module');
|
|
7
5
|
|
|
@@ -11,7 +9,7 @@ try {
|
|
|
11
9
|
} catch(error) {}
|
|
12
10
|
var src;
|
|
13
11
|
var srcEnd;
|
|
14
|
-
var position = 0;
|
|
12
|
+
var position$1 = 0;
|
|
15
13
|
const EMPTY_ARRAY = [];
|
|
16
14
|
var strings = EMPTY_ARRAY;
|
|
17
15
|
var stringPosition = 0;
|
|
@@ -20,7 +18,7 @@ var currentStructures;
|
|
|
20
18
|
var srcString;
|
|
21
19
|
var srcStringStart = 0;
|
|
22
20
|
var srcStringEnd = 0;
|
|
23
|
-
var bundledStrings;
|
|
21
|
+
var bundledStrings$1;
|
|
24
22
|
var referenceMap;
|
|
25
23
|
var currentExtensions = [];
|
|
26
24
|
var dataView;
|
|
@@ -33,7 +31,8 @@ const C1 = new C1Type();
|
|
|
33
31
|
C1.name = 'MessagePack 0xC1';
|
|
34
32
|
var sequentialMode = false;
|
|
35
33
|
var inlineObjectReadThreshold = 2;
|
|
36
|
-
var readStruct, onLoadedStructures, onSaveState;
|
|
34
|
+
var readStruct$1, onLoadedStructures$1, onSaveState;
|
|
35
|
+
// no-eval build
|
|
37
36
|
try {
|
|
38
37
|
new Function('');
|
|
39
38
|
} catch(error) {
|
|
@@ -60,29 +59,32 @@ class Unpackr {
|
|
|
60
59
|
(options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
|
|
61
60
|
options.structures.sharedLength = 0;
|
|
62
61
|
}
|
|
62
|
+
if (options.int64AsNumber) {
|
|
63
|
+
options.int64AsType = 'number';
|
|
64
|
+
}
|
|
63
65
|
}
|
|
64
66
|
Object.assign(this, options);
|
|
65
67
|
}
|
|
66
68
|
unpack(source, options) {
|
|
67
69
|
if (src) {
|
|
68
70
|
// re-entrant execution, save the state and restore it after we do this unpack
|
|
69
|
-
return saveState(() => {
|
|
71
|
+
return saveState$1(() => {
|
|
70
72
|
clearSource();
|
|
71
73
|
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
|
|
72
74
|
})
|
|
73
75
|
}
|
|
74
76
|
if (typeof options === 'object') {
|
|
75
77
|
srcEnd = options.end || source.length;
|
|
76
|
-
position = options.start || 0;
|
|
78
|
+
position$1 = options.start || 0;
|
|
77
79
|
} else {
|
|
78
|
-
position = 0;
|
|
80
|
+
position$1 = 0;
|
|
79
81
|
srcEnd = options > -1 ? options : source.length;
|
|
80
82
|
}
|
|
81
83
|
stringPosition = 0;
|
|
82
84
|
srcStringEnd = 0;
|
|
83
85
|
srcString = null;
|
|
84
86
|
strings = EMPTY_ARRAY;
|
|
85
|
-
bundledStrings = null;
|
|
87
|
+
bundledStrings$1 = null;
|
|
86
88
|
src = source;
|
|
87
89
|
// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
|
|
88
90
|
// technique for getting data from a database where it can be copied into an existing buffer instead of creating
|
|
@@ -119,8 +121,8 @@ class Unpackr {
|
|
|
119
121
|
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
|
|
120
122
|
if (forEach) {
|
|
121
123
|
forEach(value);
|
|
122
|
-
while(position < size) {
|
|
123
|
-
lastPosition = position;
|
|
124
|
+
while(position$1 < size) {
|
|
125
|
+
lastPosition = position$1;
|
|
124
126
|
if (forEach(checkedRead()) === false) {
|
|
125
127
|
return
|
|
126
128
|
}
|
|
@@ -128,8 +130,8 @@ class Unpackr {
|
|
|
128
130
|
}
|
|
129
131
|
else {
|
|
130
132
|
values = [ value ];
|
|
131
|
-
while(position < size) {
|
|
132
|
-
lastPosition = position;
|
|
133
|
+
while(position$1 < size) {
|
|
134
|
+
lastPosition = position$1;
|
|
133
135
|
values.push(checkedRead());
|
|
134
136
|
}
|
|
135
137
|
return values
|
|
@@ -144,8 +146,8 @@ class Unpackr {
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
_mergeStructures(loadedStructures, existingStructures) {
|
|
147
|
-
if (onLoadedStructures)
|
|
148
|
-
loadedStructures = onLoadedStructures.call(this, loadedStructures);
|
|
149
|
+
if (onLoadedStructures$1)
|
|
150
|
+
loadedStructures = onLoadedStructures$1.call(this, loadedStructures);
|
|
149
151
|
loadedStructures = loadedStructures || [];
|
|
150
152
|
if (Object.isFrozen(loadedStructures))
|
|
151
153
|
loadedStructures = loadedStructures.map(structure => structure.slice(0));
|
|
@@ -183,18 +185,20 @@ function checkedRead(options) {
|
|
|
183
185
|
currentStructures.length = sharedLength;
|
|
184
186
|
}
|
|
185
187
|
let result;
|
|
186
|
-
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
187
|
-
result = readStruct(src, position, srcEnd, currentUnpackr);
|
|
188
|
+
if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct$1) {
|
|
189
|
+
result = readStruct$1(src, position$1, srcEnd, currentUnpackr);
|
|
188
190
|
src = null; // dispose of this so that recursive unpack calls don't save state
|
|
189
191
|
if (!(options && options.lazy) && result)
|
|
190
192
|
result = result.toJSON();
|
|
191
|
-
position = srcEnd;
|
|
193
|
+
position$1 = srcEnd;
|
|
192
194
|
} else
|
|
193
195
|
result = read();
|
|
194
|
-
if (bundledStrings) // bundled strings to skip past
|
|
195
|
-
position = bundledStrings.postBundlePosition;
|
|
196
|
+
if (bundledStrings$1) { // bundled strings to skip past
|
|
197
|
+
position$1 = bundledStrings$1.postBundlePosition;
|
|
198
|
+
bundledStrings$1 = null;
|
|
199
|
+
}
|
|
196
200
|
|
|
197
|
-
if (position == srcEnd) {
|
|
201
|
+
if (position$1 == srcEnd) {
|
|
198
202
|
// finished reading this source, cleanup references
|
|
199
203
|
if (currentStructures && currentStructures.restoreStructures)
|
|
200
204
|
restoreStructures();
|
|
@@ -202,7 +206,7 @@ function checkedRead(options) {
|
|
|
202
206
|
src = null;
|
|
203
207
|
if (referenceMap)
|
|
204
208
|
referenceMap = null;
|
|
205
|
-
} else if (position > srcEnd) {
|
|
209
|
+
} else if (position$1 > srcEnd) {
|
|
206
210
|
// over read
|
|
207
211
|
throw new Error('Unexpected end of MessagePack data')
|
|
208
212
|
} else if (!sequentialMode) {
|
|
@@ -214,7 +218,7 @@ function checkedRead(options) {
|
|
|
214
218
|
if (currentStructures && currentStructures.restoreStructures)
|
|
215
219
|
restoreStructures();
|
|
216
220
|
clearSource();
|
|
217
|
-
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
|
|
221
|
+
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
|
|
218
222
|
error.incomplete = true;
|
|
219
223
|
}
|
|
220
224
|
throw error
|
|
@@ -229,7 +233,7 @@ function restoreStructures() {
|
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
function read() {
|
|
232
|
-
let token = src[position++];
|
|
236
|
+
let token = src[position$1++];
|
|
233
237
|
if (token < 0xa0) {
|
|
234
238
|
if (token < 0x80) {
|
|
235
239
|
if (token < 0x40)
|
|
@@ -277,8 +281,8 @@ function read() {
|
|
|
277
281
|
} else if (token < 0xc0) {
|
|
278
282
|
// fixstr
|
|
279
283
|
let length = token - 0xa0;
|
|
280
|
-
if (srcStringEnd >= position) {
|
|
281
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
284
|
+
if (srcStringEnd >= position$1) {
|
|
285
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
|
|
282
286
|
}
|
|
283
287
|
if (srcStringEnd == 0 && srcEnd < 140) {
|
|
284
288
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
@@ -292,124 +296,128 @@ function read() {
|
|
|
292
296
|
switch (token) {
|
|
293
297
|
case 0xc0: return null
|
|
294
298
|
case 0xc1:
|
|
295
|
-
if (bundledStrings) {
|
|
299
|
+
if (bundledStrings$1) {
|
|
296
300
|
value = read(); // followed by the length of the string in characters (not bytes!)
|
|
297
301
|
if (value > 0)
|
|
298
|
-
return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
|
|
302
|
+
return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
|
|
299
303
|
else
|
|
300
|
-
return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
|
|
304
|
+
return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
|
|
301
305
|
}
|
|
302
306
|
return C1; // "never-used", return special object to denote that
|
|
303
307
|
case 0xc2: return false
|
|
304
308
|
case 0xc3: return true
|
|
305
309
|
case 0xc4:
|
|
306
310
|
// bin 8
|
|
307
|
-
value = src[position++];
|
|
311
|
+
value = src[position$1++];
|
|
308
312
|
if (value === undefined)
|
|
309
313
|
throw new Error('Unexpected end of buffer')
|
|
310
314
|
return readBin(value)
|
|
311
315
|
case 0xc5:
|
|
312
316
|
// bin 16
|
|
313
|
-
value = dataView.getUint16(position);
|
|
314
|
-
position += 2;
|
|
317
|
+
value = dataView.getUint16(position$1);
|
|
318
|
+
position$1 += 2;
|
|
315
319
|
return readBin(value)
|
|
316
320
|
case 0xc6:
|
|
317
321
|
// bin 32
|
|
318
|
-
value = dataView.getUint32(position);
|
|
319
|
-
position += 4;
|
|
322
|
+
value = dataView.getUint32(position$1);
|
|
323
|
+
position$1 += 4;
|
|
320
324
|
return readBin(value)
|
|
321
325
|
case 0xc7:
|
|
322
326
|
// ext 8
|
|
323
|
-
return readExt(src[position++])
|
|
327
|
+
return readExt(src[position$1++])
|
|
324
328
|
case 0xc8:
|
|
325
329
|
// ext 16
|
|
326
|
-
value = dataView.getUint16(position);
|
|
327
|
-
position += 2;
|
|
330
|
+
value = dataView.getUint16(position$1);
|
|
331
|
+
position$1 += 2;
|
|
328
332
|
return readExt(value)
|
|
329
333
|
case 0xc9:
|
|
330
334
|
// ext 32
|
|
331
|
-
value = dataView.getUint32(position);
|
|
332
|
-
position += 4;
|
|
335
|
+
value = dataView.getUint32(position$1);
|
|
336
|
+
position$1 += 4;
|
|
333
337
|
return readExt(value)
|
|
334
338
|
case 0xca:
|
|
335
|
-
value = dataView.getFloat32(position);
|
|
339
|
+
value = dataView.getFloat32(position$1);
|
|
336
340
|
if (currentUnpackr.useFloat32 > 2) {
|
|
337
341
|
// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
338
|
-
let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
|
|
339
|
-
position += 4;
|
|
342
|
+
let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
|
|
343
|
+
position$1 += 4;
|
|
340
344
|
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
341
345
|
}
|
|
342
|
-
position += 4;
|
|
346
|
+
position$1 += 4;
|
|
343
347
|
return value
|
|
344
348
|
case 0xcb:
|
|
345
|
-
value = dataView.getFloat64(position);
|
|
346
|
-
position += 8;
|
|
349
|
+
value = dataView.getFloat64(position$1);
|
|
350
|
+
position$1 += 8;
|
|
347
351
|
return value
|
|
348
352
|
// uint handlers
|
|
349
353
|
case 0xcc:
|
|
350
|
-
return src[position++]
|
|
354
|
+
return src[position$1++]
|
|
351
355
|
case 0xcd:
|
|
352
|
-
value = dataView.getUint16(position);
|
|
353
|
-
position += 2;
|
|
356
|
+
value = dataView.getUint16(position$1);
|
|
357
|
+
position$1 += 2;
|
|
354
358
|
return value
|
|
355
359
|
case 0xce:
|
|
356
|
-
value = dataView.getUint32(position);
|
|
357
|
-
position += 4;
|
|
360
|
+
value = dataView.getUint32(position$1);
|
|
361
|
+
position$1 += 4;
|
|
358
362
|
return value
|
|
359
363
|
case 0xcf:
|
|
360
|
-
if (currentUnpackr.
|
|
361
|
-
value = dataView.getUint32(position) * 0x100000000;
|
|
362
|
-
value += dataView.getUint32(position + 4);
|
|
364
|
+
if (currentUnpackr.int64AsType === 'number') {
|
|
365
|
+
value = dataView.getUint32(position$1) * 0x100000000;
|
|
366
|
+
value += dataView.getUint32(position$1 + 4);
|
|
367
|
+
} else if (currentUnpackr.int64AsType === 'string') {
|
|
368
|
+
value = dataView.getBigUint64(position$1).toString();
|
|
363
369
|
} else
|
|
364
|
-
value = dataView.getBigUint64(position);
|
|
365
|
-
position += 8;
|
|
370
|
+
value = dataView.getBigUint64(position$1);
|
|
371
|
+
position$1 += 8;
|
|
366
372
|
return value
|
|
367
373
|
|
|
368
374
|
// int handlers
|
|
369
375
|
case 0xd0:
|
|
370
|
-
return dataView.getInt8(position++)
|
|
376
|
+
return dataView.getInt8(position$1++)
|
|
371
377
|
case 0xd1:
|
|
372
|
-
value = dataView.getInt16(position);
|
|
373
|
-
position += 2;
|
|
378
|
+
value = dataView.getInt16(position$1);
|
|
379
|
+
position$1 += 2;
|
|
374
380
|
return value
|
|
375
381
|
case 0xd2:
|
|
376
|
-
value = dataView.getInt32(position);
|
|
377
|
-
position += 4;
|
|
382
|
+
value = dataView.getInt32(position$1);
|
|
383
|
+
position$1 += 4;
|
|
378
384
|
return value
|
|
379
385
|
case 0xd3:
|
|
380
|
-
if (currentUnpackr.
|
|
381
|
-
value = dataView.getInt32(position) * 0x100000000;
|
|
382
|
-
value += dataView.getUint32(position + 4);
|
|
386
|
+
if (currentUnpackr.int64AsType === 'number') {
|
|
387
|
+
value = dataView.getInt32(position$1) * 0x100000000;
|
|
388
|
+
value += dataView.getUint32(position$1 + 4);
|
|
389
|
+
} else if (currentUnpackr.int64AsType === 'string') {
|
|
390
|
+
value = dataView.getBigInt64(position$1).toString();
|
|
383
391
|
} else
|
|
384
|
-
value = dataView.getBigInt64(position);
|
|
385
|
-
position += 8;
|
|
392
|
+
value = dataView.getBigInt64(position$1);
|
|
393
|
+
position$1 += 8;
|
|
386
394
|
return value
|
|
387
395
|
|
|
388
396
|
case 0xd4:
|
|
389
397
|
// fixext 1
|
|
390
|
-
value = src[position++];
|
|
398
|
+
value = src[position$1++];
|
|
391
399
|
if (value == 0x72) {
|
|
392
|
-
return recordDefinition(src[position++] & 0x3f)
|
|
400
|
+
return recordDefinition(src[position$1++] & 0x3f)
|
|
393
401
|
} else {
|
|
394
402
|
let extension = currentExtensions[value];
|
|
395
403
|
if (extension) {
|
|
396
404
|
if (extension.read) {
|
|
397
|
-
position++; // skip filler byte
|
|
405
|
+
position$1++; // skip filler byte
|
|
398
406
|
return extension.read(read())
|
|
399
407
|
} else if (extension.noBuffer) {
|
|
400
|
-
position++; // skip filler byte
|
|
408
|
+
position$1++; // skip filler byte
|
|
401
409
|
return extension()
|
|
402
410
|
} else
|
|
403
|
-
return extension(src.subarray(position, ++position))
|
|
411
|
+
return extension(src.subarray(position$1, ++position$1))
|
|
404
412
|
} else
|
|
405
413
|
throw new Error('Unknown extension ' + value)
|
|
406
414
|
}
|
|
407
415
|
case 0xd5:
|
|
408
416
|
// fixext 2
|
|
409
|
-
value = src[position];
|
|
417
|
+
value = src[position$1];
|
|
410
418
|
if (value == 0x72) {
|
|
411
|
-
position++;
|
|
412
|
-
return recordDefinition(src[position++] & 0x3f, src[position++])
|
|
419
|
+
position$1++;
|
|
420
|
+
return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
|
|
413
421
|
} else
|
|
414
422
|
return readExt(2)
|
|
415
423
|
case 0xd6:
|
|
@@ -423,46 +431,46 @@ function read() {
|
|
|
423
431
|
return readExt(16)
|
|
424
432
|
case 0xd9:
|
|
425
433
|
// str 8
|
|
426
|
-
value = src[position++];
|
|
427
|
-
if (srcStringEnd >= position) {
|
|
428
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
434
|
+
value = src[position$1++];
|
|
435
|
+
if (srcStringEnd >= position$1) {
|
|
436
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
429
437
|
}
|
|
430
438
|
return readString8(value)
|
|
431
439
|
case 0xda:
|
|
432
440
|
// str 16
|
|
433
|
-
value = dataView.getUint16(position);
|
|
434
|
-
position += 2;
|
|
435
|
-
if (srcStringEnd >= position) {
|
|
436
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
441
|
+
value = dataView.getUint16(position$1);
|
|
442
|
+
position$1 += 2;
|
|
443
|
+
if (srcStringEnd >= position$1) {
|
|
444
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
437
445
|
}
|
|
438
446
|
return readString16(value)
|
|
439
447
|
case 0xdb:
|
|
440
448
|
// str 32
|
|
441
|
-
value = dataView.getUint32(position);
|
|
442
|
-
position += 4;
|
|
443
|
-
if (srcStringEnd >= position) {
|
|
444
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
449
|
+
value = dataView.getUint32(position$1);
|
|
450
|
+
position$1 += 4;
|
|
451
|
+
if (srcStringEnd >= position$1) {
|
|
452
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
445
453
|
}
|
|
446
454
|
return readString32(value)
|
|
447
455
|
case 0xdc:
|
|
448
456
|
// array 16
|
|
449
|
-
value = dataView.getUint16(position);
|
|
450
|
-
position += 2;
|
|
457
|
+
value = dataView.getUint16(position$1);
|
|
458
|
+
position$1 += 2;
|
|
451
459
|
return readArray(value)
|
|
452
460
|
case 0xdd:
|
|
453
461
|
// array 32
|
|
454
|
-
value = dataView.getUint32(position);
|
|
455
|
-
position += 4;
|
|
462
|
+
value = dataView.getUint32(position$1);
|
|
463
|
+
position$1 += 4;
|
|
456
464
|
return readArray(value)
|
|
457
465
|
case 0xde:
|
|
458
466
|
// map 16
|
|
459
|
-
value = dataView.getUint16(position);
|
|
460
|
-
position += 2;
|
|
467
|
+
value = dataView.getUint16(position$1);
|
|
468
|
+
position$1 += 2;
|
|
461
469
|
return readMap(value)
|
|
462
470
|
case 0xdf:
|
|
463
471
|
// map 32
|
|
464
|
-
value = dataView.getUint32(position);
|
|
465
|
-
position += 4;
|
|
472
|
+
value = dataView.getUint32(position$1);
|
|
473
|
+
position$1 += 4;
|
|
466
474
|
return readMap(value)
|
|
467
475
|
default: // negative int
|
|
468
476
|
if (token >= 0xe0)
|
|
@@ -508,7 +516,7 @@ function createStructureReader(structure, firstId) {
|
|
|
508
516
|
|
|
509
517
|
const createSecondByteReader = (firstId, read0) => {
|
|
510
518
|
return function() {
|
|
511
|
-
let highByte = src[position++];
|
|
519
|
+
let highByte = src[position$1++];
|
|
512
520
|
if (highByte === 0)
|
|
513
521
|
return read0()
|
|
514
522
|
let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
|
|
@@ -523,7 +531,7 @@ const createSecondByteReader = (firstId, read0) => {
|
|
|
523
531
|
};
|
|
524
532
|
|
|
525
533
|
function loadStructures() {
|
|
526
|
-
let loadedStructures = saveState(() => {
|
|
534
|
+
let loadedStructures = saveState$1(() => {
|
|
527
535
|
// save the state in case getStructures modifies our buffer
|
|
528
536
|
src = null;
|
|
529
537
|
return currentUnpackr.getStructures()
|
|
@@ -547,9 +555,9 @@ function setExtractor(extractStrings) {
|
|
|
547
555
|
return function readString(length) {
|
|
548
556
|
let string = strings[stringPosition++];
|
|
549
557
|
if (string == null) {
|
|
550
|
-
if (bundledStrings)
|
|
558
|
+
if (bundledStrings$1)
|
|
551
559
|
return readStringJS(length)
|
|
552
|
-
let extraction = extractStrings(position - headerLength, srcEnd, src);
|
|
560
|
+
let extraction = extractStrings(position$1 - headerLength, srcEnd, src);
|
|
553
561
|
if (typeof extraction == 'string') {
|
|
554
562
|
string = extraction;
|
|
555
563
|
strings = EMPTY_ARRAY;
|
|
@@ -564,13 +572,13 @@ function setExtractor(extractStrings) {
|
|
|
564
572
|
}
|
|
565
573
|
let srcStringLength = string.length;
|
|
566
574
|
if (srcStringLength <= length) {
|
|
567
|
-
position += length;
|
|
575
|
+
position$1 += length;
|
|
568
576
|
return string
|
|
569
577
|
}
|
|
570
578
|
srcString = string;
|
|
571
|
-
srcStringStart = position;
|
|
572
|
-
srcStringEnd = position + srcStringLength;
|
|
573
|
-
position += length;
|
|
579
|
+
srcStringStart = position$1;
|
|
580
|
+
srcStringEnd = position$1 + srcStringLength;
|
|
581
|
+
position$1 += length;
|
|
574
582
|
return string.slice(0, length) // we know we just want the beginning
|
|
575
583
|
}
|
|
576
584
|
}
|
|
@@ -582,29 +590,29 @@ function readStringJS(length) {
|
|
|
582
590
|
return result
|
|
583
591
|
}
|
|
584
592
|
if (length > 64 && decoder)
|
|
585
|
-
return decoder.decode(src.subarray(position, position += length))
|
|
586
|
-
const end = position + length;
|
|
593
|
+
return decoder.decode(src.subarray(position$1, position$1 += length))
|
|
594
|
+
const end = position$1 + length;
|
|
587
595
|
const units = [];
|
|
588
596
|
result = '';
|
|
589
|
-
while (position < end) {
|
|
590
|
-
const byte1 = src[position++];
|
|
597
|
+
while (position$1 < end) {
|
|
598
|
+
const byte1 = src[position$1++];
|
|
591
599
|
if ((byte1 & 0x80) === 0) {
|
|
592
600
|
// 1 byte
|
|
593
601
|
units.push(byte1);
|
|
594
602
|
} else if ((byte1 & 0xe0) === 0xc0) {
|
|
595
603
|
// 2 bytes
|
|
596
|
-
const byte2 = src[position++] & 0x3f;
|
|
604
|
+
const byte2 = src[position$1++] & 0x3f;
|
|
597
605
|
units.push(((byte1 & 0x1f) << 6) | byte2);
|
|
598
606
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
599
607
|
// 3 bytes
|
|
600
|
-
const byte2 = src[position++] & 0x3f;
|
|
601
|
-
const byte3 = src[position++] & 0x3f;
|
|
608
|
+
const byte2 = src[position$1++] & 0x3f;
|
|
609
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
602
610
|
units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
|
|
603
611
|
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
604
612
|
// 4 bytes
|
|
605
|
-
const byte2 = src[position++] & 0x3f;
|
|
606
|
-
const byte3 = src[position++] & 0x3f;
|
|
607
|
-
const byte4 = src[position++] & 0x3f;
|
|
613
|
+
const byte2 = src[position$1++] & 0x3f;
|
|
614
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
615
|
+
const byte4 = src[position$1++] & 0x3f;
|
|
608
616
|
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
609
617
|
if (unit > 0xffff) {
|
|
610
618
|
unit -= 0x10000;
|
|
@@ -631,7 +639,7 @@ function readStringJS(length) {
|
|
|
631
639
|
function readString(source, start, length) {
|
|
632
640
|
let existingSrc = src;
|
|
633
641
|
src = source;
|
|
634
|
-
position = start;
|
|
642
|
+
position$1 = start;
|
|
635
643
|
try {
|
|
636
644
|
return readStringJS(length);
|
|
637
645
|
} finally {
|
|
@@ -670,12 +678,12 @@ function readMap(length) {
|
|
|
670
678
|
|
|
671
679
|
var fromCharCode = String.fromCharCode;
|
|
672
680
|
function longStringInJS(length) {
|
|
673
|
-
let start = position;
|
|
681
|
+
let start = position$1;
|
|
674
682
|
let bytes = new Array(length);
|
|
675
683
|
for (let i = 0; i < length; i++) {
|
|
676
|
-
const byte = src[position++];
|
|
684
|
+
const byte = src[position$1++];
|
|
677
685
|
if ((byte & 0x80) > 0) {
|
|
678
|
-
position = start;
|
|
686
|
+
position$1 = start;
|
|
679
687
|
return
|
|
680
688
|
}
|
|
681
689
|
bytes[i] = byte;
|
|
@@ -688,131 +696,131 @@ function shortStringInJS(length) {
|
|
|
688
696
|
if (length === 0)
|
|
689
697
|
return ''
|
|
690
698
|
else {
|
|
691
|
-
let a = src[position++];
|
|
699
|
+
let a = src[position$1++];
|
|
692
700
|
if ((a & 0x80) > 1) {
|
|
693
|
-
position -= 1;
|
|
701
|
+
position$1 -= 1;
|
|
694
702
|
return
|
|
695
703
|
}
|
|
696
704
|
return fromCharCode(a)
|
|
697
705
|
}
|
|
698
706
|
} else {
|
|
699
|
-
let a = src[position++];
|
|
700
|
-
let b = src[position++];
|
|
707
|
+
let a = src[position$1++];
|
|
708
|
+
let b = src[position$1++];
|
|
701
709
|
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
|
|
702
|
-
position -= 2;
|
|
710
|
+
position$1 -= 2;
|
|
703
711
|
return
|
|
704
712
|
}
|
|
705
713
|
if (length < 3)
|
|
706
714
|
return fromCharCode(a, b)
|
|
707
|
-
let c = src[position++];
|
|
715
|
+
let c = src[position$1++];
|
|
708
716
|
if ((c & 0x80) > 0) {
|
|
709
|
-
position -= 3;
|
|
717
|
+
position$1 -= 3;
|
|
710
718
|
return
|
|
711
719
|
}
|
|
712
720
|
return fromCharCode(a, b, c)
|
|
713
721
|
}
|
|
714
722
|
} else {
|
|
715
|
-
let a = src[position++];
|
|
716
|
-
let b = src[position++];
|
|
717
|
-
let c = src[position++];
|
|
718
|
-
let d = src[position++];
|
|
723
|
+
let a = src[position$1++];
|
|
724
|
+
let b = src[position$1++];
|
|
725
|
+
let c = src[position$1++];
|
|
726
|
+
let d = src[position$1++];
|
|
719
727
|
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
|
|
720
|
-
position -= 4;
|
|
728
|
+
position$1 -= 4;
|
|
721
729
|
return
|
|
722
730
|
}
|
|
723
731
|
if (length < 6) {
|
|
724
732
|
if (length === 4)
|
|
725
733
|
return fromCharCode(a, b, c, d)
|
|
726
734
|
else {
|
|
727
|
-
let e = src[position++];
|
|
735
|
+
let e = src[position$1++];
|
|
728
736
|
if ((e & 0x80) > 0) {
|
|
729
|
-
position -= 5;
|
|
737
|
+
position$1 -= 5;
|
|
730
738
|
return
|
|
731
739
|
}
|
|
732
740
|
return fromCharCode(a, b, c, d, e)
|
|
733
741
|
}
|
|
734
742
|
} else if (length < 8) {
|
|
735
|
-
let e = src[position++];
|
|
736
|
-
let f = src[position++];
|
|
743
|
+
let e = src[position$1++];
|
|
744
|
+
let f = src[position$1++];
|
|
737
745
|
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
|
|
738
|
-
position -= 6;
|
|
746
|
+
position$1 -= 6;
|
|
739
747
|
return
|
|
740
748
|
}
|
|
741
749
|
if (length < 7)
|
|
742
750
|
return fromCharCode(a, b, c, d, e, f)
|
|
743
|
-
let g = src[position++];
|
|
751
|
+
let g = src[position$1++];
|
|
744
752
|
if ((g & 0x80) > 0) {
|
|
745
|
-
position -= 7;
|
|
753
|
+
position$1 -= 7;
|
|
746
754
|
return
|
|
747
755
|
}
|
|
748
756
|
return fromCharCode(a, b, c, d, e, f, g)
|
|
749
757
|
} else {
|
|
750
|
-
let e = src[position++];
|
|
751
|
-
let f = src[position++];
|
|
752
|
-
let g = src[position++];
|
|
753
|
-
let h = src[position++];
|
|
758
|
+
let e = src[position$1++];
|
|
759
|
+
let f = src[position$1++];
|
|
760
|
+
let g = src[position$1++];
|
|
761
|
+
let h = src[position$1++];
|
|
754
762
|
if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
|
|
755
|
-
position -= 8;
|
|
763
|
+
position$1 -= 8;
|
|
756
764
|
return
|
|
757
765
|
}
|
|
758
766
|
if (length < 10) {
|
|
759
767
|
if (length === 8)
|
|
760
768
|
return fromCharCode(a, b, c, d, e, f, g, h)
|
|
761
769
|
else {
|
|
762
|
-
let i = src[position++];
|
|
770
|
+
let i = src[position$1++];
|
|
763
771
|
if ((i & 0x80) > 0) {
|
|
764
|
-
position -= 9;
|
|
772
|
+
position$1 -= 9;
|
|
765
773
|
return
|
|
766
774
|
}
|
|
767
775
|
return fromCharCode(a, b, c, d, e, f, g, h, i)
|
|
768
776
|
}
|
|
769
777
|
} else if (length < 12) {
|
|
770
|
-
let i = src[position++];
|
|
771
|
-
let j = src[position++];
|
|
778
|
+
let i = src[position$1++];
|
|
779
|
+
let j = src[position$1++];
|
|
772
780
|
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
|
|
773
|
-
position -= 10;
|
|
781
|
+
position$1 -= 10;
|
|
774
782
|
return
|
|
775
783
|
}
|
|
776
784
|
if (length < 11)
|
|
777
785
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j)
|
|
778
|
-
let k = src[position++];
|
|
786
|
+
let k = src[position$1++];
|
|
779
787
|
if ((k & 0x80) > 0) {
|
|
780
|
-
position -= 11;
|
|
788
|
+
position$1 -= 11;
|
|
781
789
|
return
|
|
782
790
|
}
|
|
783
791
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
|
|
784
792
|
} else {
|
|
785
|
-
let i = src[position++];
|
|
786
|
-
let j = src[position++];
|
|
787
|
-
let k = src[position++];
|
|
788
|
-
let l = src[position++];
|
|
793
|
+
let i = src[position$1++];
|
|
794
|
+
let j = src[position$1++];
|
|
795
|
+
let k = src[position$1++];
|
|
796
|
+
let l = src[position$1++];
|
|
789
797
|
if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
|
|
790
|
-
position -= 12;
|
|
798
|
+
position$1 -= 12;
|
|
791
799
|
return
|
|
792
800
|
}
|
|
793
801
|
if (length < 14) {
|
|
794
802
|
if (length === 12)
|
|
795
803
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
|
|
796
804
|
else {
|
|
797
|
-
let m = src[position++];
|
|
805
|
+
let m = src[position$1++];
|
|
798
806
|
if ((m & 0x80) > 0) {
|
|
799
|
-
position -= 13;
|
|
807
|
+
position$1 -= 13;
|
|
800
808
|
return
|
|
801
809
|
}
|
|
802
810
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
|
|
803
811
|
}
|
|
804
812
|
} else {
|
|
805
|
-
let m = src[position++];
|
|
806
|
-
let n = src[position++];
|
|
813
|
+
let m = src[position$1++];
|
|
814
|
+
let n = src[position$1++];
|
|
807
815
|
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
|
|
808
|
-
position -= 14;
|
|
816
|
+
position$1 -= 14;
|
|
809
817
|
return
|
|
810
818
|
}
|
|
811
819
|
if (length < 15)
|
|
812
820
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
|
|
813
|
-
let o = src[position++];
|
|
821
|
+
let o = src[position$1++];
|
|
814
822
|
if ((o & 0x80) > 0) {
|
|
815
|
-
position -= 15;
|
|
823
|
+
position$1 -= 15;
|
|
816
824
|
return
|
|
817
825
|
}
|
|
818
826
|
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
|
|
@@ -823,7 +831,7 @@ function shortStringInJS(length) {
|
|
|
823
831
|
}
|
|
824
832
|
|
|
825
833
|
function readOnlyJSString() {
|
|
826
|
-
let token = src[position++];
|
|
834
|
+
let token = src[position$1++];
|
|
827
835
|
let length;
|
|
828
836
|
if (token < 0xc0) {
|
|
829
837
|
// fixstr
|
|
@@ -832,17 +840,17 @@ function readOnlyJSString() {
|
|
|
832
840
|
switch(token) {
|
|
833
841
|
case 0xd9:
|
|
834
842
|
// str 8
|
|
835
|
-
length = src[position++];
|
|
843
|
+
length = src[position$1++];
|
|
836
844
|
break
|
|
837
845
|
case 0xda:
|
|
838
846
|
// str 16
|
|
839
|
-
length = dataView.getUint16(position);
|
|
840
|
-
position += 2;
|
|
847
|
+
length = dataView.getUint16(position$1);
|
|
848
|
+
position$1 += 2;
|
|
841
849
|
break
|
|
842
850
|
case 0xdb:
|
|
843
851
|
// str 32
|
|
844
|
-
length = dataView.getUint32(position);
|
|
845
|
-
position += 4;
|
|
852
|
+
length = dataView.getUint32(position$1);
|
|
853
|
+
position$1 += 4;
|
|
846
854
|
break
|
|
847
855
|
default:
|
|
848
856
|
throw new Error('Expected string')
|
|
@@ -855,44 +863,44 @@ function readOnlyJSString() {
|
|
|
855
863
|
function readBin(length) {
|
|
856
864
|
return currentUnpackr.copyBuffers ?
|
|
857
865
|
// specifically use the copying slice (not the node one)
|
|
858
|
-
Uint8Array.prototype.slice.call(src, position, position += length) :
|
|
859
|
-
src.subarray(position, position += length)
|
|
866
|
+
Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
|
|
867
|
+
src.subarray(position$1, position$1 += length)
|
|
860
868
|
}
|
|
861
869
|
function readExt(length) {
|
|
862
|
-
let type = src[position++];
|
|
870
|
+
let type = src[position$1++];
|
|
863
871
|
if (currentExtensions[type]) {
|
|
864
872
|
let end;
|
|
865
|
-
return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
|
|
866
|
-
position = readPosition;
|
|
873
|
+
return currentExtensions[type](src.subarray(position$1, end = (position$1 += length)), (readPosition) => {
|
|
874
|
+
position$1 = readPosition;
|
|
867
875
|
try {
|
|
868
876
|
return read();
|
|
869
877
|
} finally {
|
|
870
|
-
position = end;
|
|
878
|
+
position$1 = end;
|
|
871
879
|
}
|
|
872
880
|
})
|
|
873
881
|
}
|
|
874
882
|
else
|
|
875
|
-
throw new Error('Unknown extension type ' + type)
|
|
883
|
+
throw new Error('Unknown extension type ' + type)
|
|
876
884
|
}
|
|
877
885
|
|
|
878
886
|
var keyCache = new Array(4096);
|
|
879
887
|
function readKey() {
|
|
880
|
-
let length = src[position++];
|
|
888
|
+
let length = src[position$1++];
|
|
881
889
|
if (length >= 0xa0 && length < 0xc0) {
|
|
882
890
|
// fixstr, potentially use key cache
|
|
883
891
|
length = length - 0xa0;
|
|
884
|
-
if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
|
|
885
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
892
|
+
if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
|
|
893
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
|
|
886
894
|
else if (!(srcStringEnd == 0 && srcEnd < 180))
|
|
887
895
|
return readFixedString(length)
|
|
888
896
|
} else { // not cacheable, go back and do a standard read
|
|
889
|
-
position--;
|
|
897
|
+
position$1--;
|
|
890
898
|
return read().toString()
|
|
891
899
|
}
|
|
892
|
-
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
|
|
900
|
+
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
|
|
893
901
|
let entry = keyCache[key];
|
|
894
|
-
let checkPosition = position;
|
|
895
|
-
let end = position + length - 3;
|
|
902
|
+
let checkPosition = position$1;
|
|
903
|
+
let end = position$1 + length - 3;
|
|
896
904
|
let chunk;
|
|
897
905
|
let i = 0;
|
|
898
906
|
if (entry && entry.bytes == length) {
|
|
@@ -913,11 +921,11 @@ function readKey() {
|
|
|
913
921
|
}
|
|
914
922
|
}
|
|
915
923
|
if (checkPosition === end) {
|
|
916
|
-
position = checkPosition;
|
|
924
|
+
position$1 = checkPosition;
|
|
917
925
|
return entry.string
|
|
918
926
|
}
|
|
919
927
|
end -= 3;
|
|
920
|
-
checkPosition = position;
|
|
928
|
+
checkPosition = position$1;
|
|
921
929
|
}
|
|
922
930
|
entry = [];
|
|
923
931
|
keyCache[key] = entry;
|
|
@@ -965,10 +973,10 @@ currentExtensions[0x65] = () => {
|
|
|
965
973
|
|
|
966
974
|
currentExtensions[0x69] = (data) => {
|
|
967
975
|
// id extension (for structured clones)
|
|
968
|
-
let id = dataView.getUint32(position - 4);
|
|
976
|
+
let id = dataView.getUint32(position$1 - 4);
|
|
969
977
|
if (!referenceMap)
|
|
970
978
|
referenceMap = new Map();
|
|
971
|
-
let token = src[position];
|
|
979
|
+
let token = src[position$1];
|
|
972
980
|
let target;
|
|
973
981
|
// TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
|
|
974
982
|
// ahead past references to record structure definitions
|
|
@@ -988,7 +996,7 @@ currentExtensions[0x69] = (data) => {
|
|
|
988
996
|
|
|
989
997
|
currentExtensions[0x70] = (data) => {
|
|
990
998
|
// pointer extension (for structured clones)
|
|
991
|
-
let id = dataView.getUint32(position - 4);
|
|
999
|
+
let id = dataView.getUint32(position$1 - 4);
|
|
992
1000
|
let refEntry = referenceMap.get(id);
|
|
993
1001
|
refEntry.used = true;
|
|
994
1002
|
return refEntry.target
|
|
@@ -1013,14 +1021,14 @@ currentExtensions[0x78] = () => {
|
|
|
1013
1021
|
const TEMP_BUNDLE = [];
|
|
1014
1022
|
currentExtensions[0x62] = (data) => {
|
|
1015
1023
|
let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
|
|
1016
|
-
let dataPosition = position;
|
|
1017
|
-
position += dataSize - data.length;
|
|
1018
|
-
bundledStrings = TEMP_BUNDLE;
|
|
1019
|
-
bundledStrings = [readOnlyJSString(), readOnlyJSString()];
|
|
1020
|
-
bundledStrings.position0 = 0;
|
|
1021
|
-
bundledStrings.position1 = 0;
|
|
1022
|
-
bundledStrings.postBundlePosition = position;
|
|
1023
|
-
position = dataPosition;
|
|
1024
|
+
let dataPosition = position$1;
|
|
1025
|
+
position$1 += dataSize - data.length;
|
|
1026
|
+
bundledStrings$1 = TEMP_BUNDLE;
|
|
1027
|
+
bundledStrings$1 = [readOnlyJSString(), readOnlyJSString()];
|
|
1028
|
+
bundledStrings$1.position0 = 0;
|
|
1029
|
+
bundledStrings$1.position1 = 0;
|
|
1030
|
+
bundledStrings$1.postBundlePosition = position$1;
|
|
1031
|
+
position$1 = dataPosition;
|
|
1024
1032
|
return read()
|
|
1025
1033
|
};
|
|
1026
1034
|
|
|
@@ -1042,18 +1050,18 @@ currentExtensions[0xff] = (data) => {
|
|
|
1042
1050
|
// registration of bulk record definition?
|
|
1043
1051
|
// currentExtensions[0x52] = () =>
|
|
1044
1052
|
|
|
1045
|
-
function saveState(callback) {
|
|
1053
|
+
function saveState$1(callback) {
|
|
1046
1054
|
if (onSaveState)
|
|
1047
1055
|
onSaveState();
|
|
1048
1056
|
let savedSrcEnd = srcEnd;
|
|
1049
|
-
let savedPosition = position;
|
|
1057
|
+
let savedPosition = position$1;
|
|
1050
1058
|
let savedStringPosition = stringPosition;
|
|
1051
1059
|
let savedSrcStringStart = srcStringStart;
|
|
1052
1060
|
let savedSrcStringEnd = srcStringEnd;
|
|
1053
1061
|
let savedSrcString = srcString;
|
|
1054
1062
|
let savedStrings = strings;
|
|
1055
1063
|
let savedReferenceMap = referenceMap;
|
|
1056
|
-
let savedBundledStrings = bundledStrings;
|
|
1064
|
+
let savedBundledStrings = bundledStrings$1;
|
|
1057
1065
|
|
|
1058
1066
|
// TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
|
|
1059
1067
|
let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
|
|
@@ -1063,14 +1071,14 @@ function saveState(callback) {
|
|
|
1063
1071
|
let savedSequentialMode = sequentialMode;
|
|
1064
1072
|
let value = callback();
|
|
1065
1073
|
srcEnd = savedSrcEnd;
|
|
1066
|
-
position = savedPosition;
|
|
1074
|
+
position$1 = savedPosition;
|
|
1067
1075
|
stringPosition = savedStringPosition;
|
|
1068
1076
|
srcStringStart = savedSrcStringStart;
|
|
1069
1077
|
srcStringEnd = savedSrcStringEnd;
|
|
1070
1078
|
srcString = savedSrcString;
|
|
1071
1079
|
strings = savedStrings;
|
|
1072
1080
|
referenceMap = savedReferenceMap;
|
|
1073
|
-
bundledStrings = savedBundledStrings;
|
|
1081
|
+
bundledStrings$1 = savedBundledStrings;
|
|
1074
1082
|
src = savedSrc;
|
|
1075
1083
|
sequentialMode = savedSequentialMode;
|
|
1076
1084
|
currentStructures = savedStructures;
|
|
@@ -1085,7 +1093,7 @@ function clearSource() {
|
|
|
1085
1093
|
currentStructures = null;
|
|
1086
1094
|
}
|
|
1087
1095
|
|
|
1088
|
-
function addExtension(extension) {
|
|
1096
|
+
function addExtension$1(extension) {
|
|
1089
1097
|
if (extension.unpack)
|
|
1090
1098
|
currentExtensions[extension.type] = extension.unpack;
|
|
1091
1099
|
else
|
|
@@ -1115,26 +1123,26 @@ function roundFloat32(float32Number) {
|
|
|
1115
1123
|
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
1116
1124
|
}
|
|
1117
1125
|
function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
|
|
1118
|
-
readStruct = updatedReadStruct;
|
|
1119
|
-
onLoadedStructures = loadedStructs;
|
|
1126
|
+
readStruct$1 = updatedReadStruct;
|
|
1127
|
+
onLoadedStructures$1 = loadedStructs;
|
|
1120
1128
|
onSaveState = saveState;
|
|
1121
1129
|
}
|
|
1122
1130
|
|
|
1123
|
-
let textEncoder;
|
|
1131
|
+
let textEncoder$1;
|
|
1124
1132
|
try {
|
|
1125
|
-
textEncoder = new TextEncoder();
|
|
1133
|
+
textEncoder$1 = new TextEncoder();
|
|
1126
1134
|
} catch (error) {}
|
|
1127
1135
|
let extensions, extensionClasses;
|
|
1128
|
-
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
|
1129
|
-
const ByteArrayAllocate = hasNodeBuffer ?
|
|
1136
|
+
const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
|
|
1137
|
+
const ByteArrayAllocate = hasNodeBuffer$1 ?
|
|
1130
1138
|
function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
|
|
1131
|
-
const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
|
|
1132
|
-
const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
|
|
1139
|
+
const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
|
|
1140
|
+
const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
|
|
1133
1141
|
let target, keysTarget;
|
|
1134
1142
|
let targetView;
|
|
1135
|
-
let position
|
|
1143
|
+
let position = 0;
|
|
1136
1144
|
let safeEnd;
|
|
1137
|
-
let bundledStrings
|
|
1145
|
+
let bundledStrings = null;
|
|
1138
1146
|
let writeStructSlots;
|
|
1139
1147
|
const MAX_BUNDLE_SIZE = 0xf000;
|
|
1140
1148
|
const hasNonLatin = /[\u0080-\uFFFF]/;
|
|
@@ -1149,9 +1157,9 @@ class Packr extends Unpackr {
|
|
|
1149
1157
|
let referenceMap;
|
|
1150
1158
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1151
1159
|
return target.utf8Write(string, position, 0xffffffff)
|
|
1152
|
-
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1160
|
+
} : (textEncoder$1 && textEncoder$1.encodeInto) ?
|
|
1153
1161
|
function(string, position) {
|
|
1154
|
-
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
1162
|
+
return textEncoder$1.encodeInto(string, target.subarray(position)).written
|
|
1155
1163
|
} : false;
|
|
1156
1164
|
|
|
1157
1165
|
let packr = this;
|
|
@@ -1186,25 +1194,25 @@ class Packr extends Unpackr {
|
|
|
1186
1194
|
this.pack = this.encode = function(value, encodeOptions) {
|
|
1187
1195
|
if (!target) {
|
|
1188
1196
|
target = new ByteArrayAllocate(8192);
|
|
1189
|
-
targetView = target.dataView = new DataView(target.buffer, 0, 8192);
|
|
1190
|
-
position
|
|
1197
|
+
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192));
|
|
1198
|
+
position = 0;
|
|
1191
1199
|
}
|
|
1192
1200
|
safeEnd = target.length - 10;
|
|
1193
|
-
if (safeEnd - position
|
|
1201
|
+
if (safeEnd - position < 0x800) {
|
|
1194
1202
|
// don't start too close to the end,
|
|
1195
1203
|
target = new ByteArrayAllocate(target.length);
|
|
1196
|
-
targetView = target.dataView = new DataView(target.buffer, 0, target.length);
|
|
1204
|
+
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
|
|
1197
1205
|
safeEnd = target.length - 10;
|
|
1198
|
-
position
|
|
1206
|
+
position = 0;
|
|
1199
1207
|
} else
|
|
1200
|
-
position
|
|
1201
|
-
start = position
|
|
1208
|
+
position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
|
|
1209
|
+
start = position;
|
|
1202
1210
|
referenceMap = packr.structuredClone ? new Map() : null;
|
|
1203
1211
|
if (packr.bundleStrings && typeof value !== 'string') {
|
|
1204
|
-
bundledStrings
|
|
1205
|
-
bundledStrings
|
|
1212
|
+
bundledStrings = [];
|
|
1213
|
+
bundledStrings.size = Infinity; // force a new bundle start on first string
|
|
1206
1214
|
} else
|
|
1207
|
-
bundledStrings
|
|
1215
|
+
bundledStrings = null;
|
|
1208
1216
|
structures = packr.structures;
|
|
1209
1217
|
if (structures) {
|
|
1210
1218
|
if (structures.uninitialized)
|
|
@@ -1245,8 +1253,8 @@ class Packr extends Unpackr {
|
|
|
1245
1253
|
writeStruct(value);
|
|
1246
1254
|
else
|
|
1247
1255
|
pack(value);
|
|
1248
|
-
let lastBundle = bundledStrings
|
|
1249
|
-
if (bundledStrings
|
|
1256
|
+
let lastBundle = bundledStrings;
|
|
1257
|
+
if (bundledStrings)
|
|
1250
1258
|
writeBundles(start, pack, 0);
|
|
1251
1259
|
if (referenceMap && referenceMap.idsToInsert) {
|
|
1252
1260
|
let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
|
|
@@ -1275,21 +1283,21 @@ class Packr extends Unpackr {
|
|
|
1275
1283
|
targetView.setUint32(lastBundle.position + start,
|
|
1276
1284
|
targetView.getUint32(lastBundle.position + start) + incrementPosition);
|
|
1277
1285
|
}
|
|
1278
|
-
position
|
|
1279
|
-
if (position
|
|
1280
|
-
makeRoom(position
|
|
1281
|
-
packr.offset = position
|
|
1282
|
-
let serialized = insertIds(target.subarray(start, position
|
|
1286
|
+
position += idsToInsert.length * 6;
|
|
1287
|
+
if (position > safeEnd)
|
|
1288
|
+
makeRoom(position);
|
|
1289
|
+
packr.offset = position;
|
|
1290
|
+
let serialized = insertIds(target.subarray(start, position), idsToInsert);
|
|
1283
1291
|
referenceMap = null;
|
|
1284
1292
|
return serialized
|
|
1285
1293
|
}
|
|
1286
|
-
packr.offset = position
|
|
1294
|
+
packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1287
1295
|
if (encodeOptions & REUSE_BUFFER_MODE) {
|
|
1288
1296
|
target.start = start;
|
|
1289
|
-
target.end = position
|
|
1297
|
+
target.end = position;
|
|
1290
1298
|
return target
|
|
1291
1299
|
}
|
|
1292
|
-
return target.subarray(start, position
|
|
1300
|
+
return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
|
|
1293
1301
|
} finally {
|
|
1294
1302
|
if (structures) {
|
|
1295
1303
|
if (serializationsSinceTransitionRebuild < 10)
|
|
@@ -1312,8 +1320,8 @@ class Packr extends Unpackr {
|
|
|
1312
1320
|
}
|
|
1313
1321
|
if (hasSharedUpdate && packr.saveStructures) {
|
|
1314
1322
|
// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
1315
|
-
let returnBuffer = target.subarray(start, position
|
|
1316
|
-
let newSharedData = prepareStructures(structures, packr);
|
|
1323
|
+
let returnBuffer = target.subarray(start, position);
|
|
1324
|
+
let newSharedData = prepareStructures$1(structures, packr);
|
|
1317
1325
|
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
|
|
1318
1326
|
// get updated structures and try again if the update failed
|
|
1319
1327
|
return packr.pack(value)
|
|
@@ -1323,47 +1331,47 @@ class Packr extends Unpackr {
|
|
|
1323
1331
|
}
|
|
1324
1332
|
}
|
|
1325
1333
|
if (encodeOptions & RESET_BUFFER_MODE)
|
|
1326
|
-
position
|
|
1334
|
+
position = start;
|
|
1327
1335
|
}
|
|
1328
1336
|
};
|
|
1329
1337
|
const pack = (value) => {
|
|
1330
|
-
if (position
|
|
1331
|
-
target = makeRoom(position
|
|
1338
|
+
if (position > safeEnd)
|
|
1339
|
+
target = makeRoom(position);
|
|
1332
1340
|
|
|
1333
1341
|
var type = typeof value;
|
|
1334
1342
|
var length;
|
|
1335
1343
|
if (type === 'string') {
|
|
1336
1344
|
let strLength = value.length;
|
|
1337
|
-
if (bundledStrings
|
|
1338
|
-
if ((bundledStrings
|
|
1345
|
+
if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
|
|
1346
|
+
if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
|
|
1339
1347
|
let extStart;
|
|
1340
|
-
let maxBytes = (bundledStrings
|
|
1341
|
-
if (position
|
|
1342
|
-
target = makeRoom(position
|
|
1348
|
+
let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10;
|
|
1349
|
+
if (position + maxBytes > safeEnd)
|
|
1350
|
+
target = makeRoom(position + maxBytes);
|
|
1343
1351
|
let lastBundle;
|
|
1344
|
-
if (bundledStrings
|
|
1345
|
-
lastBundle = bundledStrings
|
|
1346
|
-
target[position
|
|
1347
|
-
position
|
|
1348
|
-
target[position
|
|
1349
|
-
extStart = position
|
|
1350
|
-
position
|
|
1352
|
+
if (bundledStrings.position) { // here we use the 0x62 extension to write the last bundle and reserve space for the reference pointer to the next/current bundle
|
|
1353
|
+
lastBundle = bundledStrings;
|
|
1354
|
+
target[position] = 0xc8; // ext 16
|
|
1355
|
+
position += 3; // reserve for the writing bundle size
|
|
1356
|
+
target[position++] = 0x62; // 'b'
|
|
1357
|
+
extStart = position - start;
|
|
1358
|
+
position += 4; // reserve for writing bundle reference
|
|
1351
1359
|
writeBundles(start, pack, 0); // write the last bundles
|
|
1352
|
-
targetView.setUint16(extStart + start - 3, position
|
|
1360
|
+
targetView.setUint16(extStart + start - 3, position - start - extStart);
|
|
1353
1361
|
} else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
|
|
1354
|
-
target[position
|
|
1355
|
-
target[position
|
|
1356
|
-
extStart = position
|
|
1357
|
-
position
|
|
1362
|
+
target[position++] = 0xd6; // fixext 4
|
|
1363
|
+
target[position++] = 0x62; // 'b'
|
|
1364
|
+
extStart = position - start;
|
|
1365
|
+
position += 4; // reserve for writing bundle reference
|
|
1358
1366
|
}
|
|
1359
|
-
bundledStrings
|
|
1360
|
-
bundledStrings
|
|
1361
|
-
bundledStrings
|
|
1362
|
-
bundledStrings
|
|
1367
|
+
bundledStrings = ['', '']; // create new ones
|
|
1368
|
+
bundledStrings.previous = lastBundle;
|
|
1369
|
+
bundledStrings.size = 0;
|
|
1370
|
+
bundledStrings.position = extStart;
|
|
1363
1371
|
}
|
|
1364
1372
|
let twoByte = hasNonLatin.test(value);
|
|
1365
|
-
bundledStrings
|
|
1366
|
-
target[position
|
|
1373
|
+
bundledStrings[twoByte ? 0 : 1] += value;
|
|
1374
|
+
target[position++] = 0xc1;
|
|
1367
1375
|
pack(twoByte ? -strLength : strLength);
|
|
1368
1376
|
return
|
|
1369
1377
|
}
|
|
@@ -1379,11 +1387,11 @@ class Packr extends Unpackr {
|
|
|
1379
1387
|
headerSize = 5;
|
|
1380
1388
|
}
|
|
1381
1389
|
let maxBytes = strLength * 3;
|
|
1382
|
-
if (position
|
|
1383
|
-
target = makeRoom(position
|
|
1390
|
+
if (position + maxBytes > safeEnd)
|
|
1391
|
+
target = makeRoom(position + maxBytes);
|
|
1384
1392
|
|
|
1385
1393
|
if (strLength < 0x40 || !encodeUtf8) {
|
|
1386
|
-
let i, c1, c2, strPosition = position
|
|
1394
|
+
let i, c1, c2, strPosition = position + headerSize;
|
|
1387
1395
|
for (i = 0; i < strLength; i++) {
|
|
1388
1396
|
c1 = value.charCodeAt(i);
|
|
1389
1397
|
if (c1 < 0x80) {
|
|
@@ -1407,88 +1415,88 @@ class Packr extends Unpackr {
|
|
|
1407
1415
|
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
1408
1416
|
}
|
|
1409
1417
|
}
|
|
1410
|
-
length = strPosition - position
|
|
1418
|
+
length = strPosition - position - headerSize;
|
|
1411
1419
|
} else {
|
|
1412
|
-
length = encodeUtf8(value, position
|
|
1420
|
+
length = encodeUtf8(value, position + headerSize);
|
|
1413
1421
|
}
|
|
1414
1422
|
|
|
1415
1423
|
if (length < 0x20) {
|
|
1416
|
-
target[position
|
|
1424
|
+
target[position++] = 0xa0 | length;
|
|
1417
1425
|
} else if (length < 0x100) {
|
|
1418
1426
|
if (headerSize < 2) {
|
|
1419
|
-
target.copyWithin(position
|
|
1427
|
+
target.copyWithin(position + 2, position + 1, position + 1 + length);
|
|
1420
1428
|
}
|
|
1421
|
-
target[position
|
|
1422
|
-
target[position
|
|
1429
|
+
target[position++] = 0xd9;
|
|
1430
|
+
target[position++] = length;
|
|
1423
1431
|
} else if (length < 0x10000) {
|
|
1424
1432
|
if (headerSize < 3) {
|
|
1425
|
-
target.copyWithin(position
|
|
1433
|
+
target.copyWithin(position + 3, position + 2, position + 2 + length);
|
|
1426
1434
|
}
|
|
1427
|
-
target[position
|
|
1428
|
-
target[position
|
|
1429
|
-
target[position
|
|
1435
|
+
target[position++] = 0xda;
|
|
1436
|
+
target[position++] = length >> 8;
|
|
1437
|
+
target[position++] = length & 0xff;
|
|
1430
1438
|
} else {
|
|
1431
1439
|
if (headerSize < 5) {
|
|
1432
|
-
target.copyWithin(position
|
|
1440
|
+
target.copyWithin(position + 5, position + 3, position + 3 + length);
|
|
1433
1441
|
}
|
|
1434
|
-
target[position
|
|
1435
|
-
targetView.setUint32(position
|
|
1436
|
-
position
|
|
1442
|
+
target[position++] = 0xdb;
|
|
1443
|
+
targetView.setUint32(position, length);
|
|
1444
|
+
position += 4;
|
|
1437
1445
|
}
|
|
1438
|
-
position
|
|
1446
|
+
position += length;
|
|
1439
1447
|
} else if (type === 'number') {
|
|
1440
1448
|
if (value >>> 0 === value) {// positive integer, 32-bit or less
|
|
1441
1449
|
// positive uint
|
|
1442
1450
|
if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
|
|
1443
|
-
target[position
|
|
1451
|
+
target[position++] = value;
|
|
1444
1452
|
} else if (value < 0x100) {
|
|
1445
|
-
target[position
|
|
1446
|
-
target[position
|
|
1453
|
+
target[position++] = 0xcc;
|
|
1454
|
+
target[position++] = value;
|
|
1447
1455
|
} else if (value < 0x10000) {
|
|
1448
|
-
target[position
|
|
1449
|
-
target[position
|
|
1450
|
-
target[position
|
|
1456
|
+
target[position++] = 0xcd;
|
|
1457
|
+
target[position++] = value >> 8;
|
|
1458
|
+
target[position++] = value & 0xff;
|
|
1451
1459
|
} else {
|
|
1452
|
-
target[position
|
|
1453
|
-
targetView.setUint32(position
|
|
1454
|
-
position
|
|
1460
|
+
target[position++] = 0xce;
|
|
1461
|
+
targetView.setUint32(position, value);
|
|
1462
|
+
position += 4;
|
|
1455
1463
|
}
|
|
1456
1464
|
} else if (value >> 0 === value) { // negative integer
|
|
1457
1465
|
if (value >= -0x20) {
|
|
1458
|
-
target[position
|
|
1466
|
+
target[position++] = 0x100 + value;
|
|
1459
1467
|
} else if (value >= -0x80) {
|
|
1460
|
-
target[position
|
|
1461
|
-
target[position
|
|
1468
|
+
target[position++] = 0xd0;
|
|
1469
|
+
target[position++] = value + 0x100;
|
|
1462
1470
|
} else if (value >= -0x8000) {
|
|
1463
|
-
target[position
|
|
1464
|
-
targetView.setInt16(position
|
|
1465
|
-
position
|
|
1471
|
+
target[position++] = 0xd1;
|
|
1472
|
+
targetView.setInt16(position, value);
|
|
1473
|
+
position += 2;
|
|
1466
1474
|
} else {
|
|
1467
|
-
target[position
|
|
1468
|
-
targetView.setInt32(position
|
|
1469
|
-
position
|
|
1475
|
+
target[position++] = 0xd2;
|
|
1476
|
+
targetView.setInt32(position, value);
|
|
1477
|
+
position += 4;
|
|
1470
1478
|
}
|
|
1471
1479
|
} else {
|
|
1472
1480
|
let useFloat32;
|
|
1473
1481
|
if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
|
|
1474
|
-
target[position
|
|
1475
|
-
targetView.setFloat32(position
|
|
1482
|
+
target[position++] = 0xca;
|
|
1483
|
+
targetView.setFloat32(position, value);
|
|
1476
1484
|
let xShifted;
|
|
1477
1485
|
if (useFloat32 < 4 ||
|
|
1478
1486
|
// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
1479
|
-
((xShifted = value * mult10[((target[position
|
|
1480
|
-
position
|
|
1487
|
+
((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
|
|
1488
|
+
position += 4;
|
|
1481
1489
|
return
|
|
1482
1490
|
} else
|
|
1483
|
-
position
|
|
1491
|
+
position--; // move back into position for writing a double
|
|
1484
1492
|
}
|
|
1485
|
-
target[position
|
|
1486
|
-
targetView.setFloat64(position
|
|
1487
|
-
position
|
|
1493
|
+
target[position++] = 0xcb;
|
|
1494
|
+
targetView.setFloat64(position, value);
|
|
1495
|
+
position += 8;
|
|
1488
1496
|
}
|
|
1489
1497
|
} else if (type === 'object') {
|
|
1490
1498
|
if (!value)
|
|
1491
|
-
target[position
|
|
1499
|
+
target[position++] = 0xc0;
|
|
1492
1500
|
else {
|
|
1493
1501
|
if (referenceMap) {
|
|
1494
1502
|
let referee = referenceMap.get(value);
|
|
@@ -1497,29 +1505,29 @@ class Packr extends Unpackr {
|
|
|
1497
1505
|
let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
|
|
1498
1506
|
referee.id = idsToInsert.push(referee);
|
|
1499
1507
|
}
|
|
1500
|
-
target[position
|
|
1501
|
-
target[position
|
|
1502
|
-
targetView.setUint32(position
|
|
1503
|
-
position
|
|
1508
|
+
target[position++] = 0xd6; // fixext 4
|
|
1509
|
+
target[position++] = 0x70; // "p" for pointer
|
|
1510
|
+
targetView.setUint32(position, referee.id);
|
|
1511
|
+
position += 4;
|
|
1504
1512
|
return
|
|
1505
1513
|
} else
|
|
1506
|
-
referenceMap.set(value, { offset: position
|
|
1514
|
+
referenceMap.set(value, { offset: position - start });
|
|
1507
1515
|
}
|
|
1508
1516
|
let constructor = value.constructor;
|
|
1509
1517
|
if (constructor === Object) {
|
|
1510
1518
|
writeObject(value, true);
|
|
1511
|
-
} else if (constructor === Array) {
|
|
1519
|
+
} else if (constructor === Array || Array.isArray(value)) {
|
|
1512
1520
|
length = value.length;
|
|
1513
1521
|
if (length < 0x10) {
|
|
1514
|
-
target[position
|
|
1522
|
+
target[position++] = 0x90 | length;
|
|
1515
1523
|
} else if (length < 0x10000) {
|
|
1516
|
-
target[position
|
|
1517
|
-
target[position
|
|
1518
|
-
target[position
|
|
1524
|
+
target[position++] = 0xdc;
|
|
1525
|
+
target[position++] = length >> 8;
|
|
1526
|
+
target[position++] = length & 0xff;
|
|
1519
1527
|
} else {
|
|
1520
|
-
target[position
|
|
1521
|
-
targetView.setUint32(position
|
|
1522
|
-
position
|
|
1528
|
+
target[position++] = 0xdd;
|
|
1529
|
+
targetView.setUint32(position, length);
|
|
1530
|
+
position += 4;
|
|
1523
1531
|
}
|
|
1524
1532
|
for (let i = 0; i < length; i++) {
|
|
1525
1533
|
pack(value[i]);
|
|
@@ -1527,15 +1535,15 @@ class Packr extends Unpackr {
|
|
|
1527
1535
|
} else if (constructor === Map) {
|
|
1528
1536
|
length = value.size;
|
|
1529
1537
|
if (length < 0x10) {
|
|
1530
|
-
target[position
|
|
1538
|
+
target[position++] = 0x80 | length;
|
|
1531
1539
|
} else if (length < 0x10000) {
|
|
1532
|
-
target[position
|
|
1533
|
-
target[position
|
|
1534
|
-
target[position
|
|
1540
|
+
target[position++] = 0xde;
|
|
1541
|
+
target[position++] = length >> 8;
|
|
1542
|
+
target[position++] = length & 0xff;
|
|
1535
1543
|
} else {
|
|
1536
|
-
target[position
|
|
1537
|
-
targetView.setUint32(position
|
|
1538
|
-
position
|
|
1544
|
+
target[position++] = 0xdf;
|
|
1545
|
+
targetView.setUint32(position, length);
|
|
1546
|
+
position += 4;
|
|
1539
1547
|
}
|
|
1540
1548
|
for (let [ key, entryValue ] of value) {
|
|
1541
1549
|
pack(key);
|
|
@@ -1548,16 +1556,16 @@ class Packr extends Unpackr {
|
|
|
1548
1556
|
let extension = extensions[i];
|
|
1549
1557
|
if (extension.write) {
|
|
1550
1558
|
if (extension.type) {
|
|
1551
|
-
target[position
|
|
1552
|
-
target[position
|
|
1553
|
-
target[position
|
|
1559
|
+
target[position++] = 0xd4; // one byte "tag" extension
|
|
1560
|
+
target[position++] = extension.type;
|
|
1561
|
+
target[position++] = 0;
|
|
1554
1562
|
}
|
|
1555
1563
|
pack(extension.write.call(this, value));
|
|
1556
1564
|
return
|
|
1557
1565
|
}
|
|
1558
1566
|
let currentTarget = target;
|
|
1559
1567
|
let currentTargetView = targetView;
|
|
1560
|
-
let currentPosition = position
|
|
1568
|
+
let currentPosition = position;
|
|
1561
1569
|
target = null;
|
|
1562
1570
|
let result;
|
|
1563
1571
|
try {
|
|
@@ -1565,11 +1573,11 @@ class Packr extends Unpackr {
|
|
|
1565
1573
|
// restore target and use it
|
|
1566
1574
|
target = currentTarget;
|
|
1567
1575
|
currentTarget = null;
|
|
1568
|
-
position
|
|
1569
|
-
if (position
|
|
1570
|
-
makeRoom(position
|
|
1576
|
+
position += size;
|
|
1577
|
+
if (position > safeEnd)
|
|
1578
|
+
makeRoom(position);
|
|
1571
1579
|
return {
|
|
1572
|
-
target, targetView, position: position
|
|
1580
|
+
target, targetView, position: position - size
|
|
1573
1581
|
}
|
|
1574
1582
|
}, pack);
|
|
1575
1583
|
} finally {
|
|
@@ -1577,14 +1585,14 @@ class Packr extends Unpackr {
|
|
|
1577
1585
|
if (currentTarget) {
|
|
1578
1586
|
target = currentTarget;
|
|
1579
1587
|
targetView = currentTargetView;
|
|
1580
|
-
position
|
|
1588
|
+
position = currentPosition;
|
|
1581
1589
|
safeEnd = target.length - 10;
|
|
1582
1590
|
}
|
|
1583
1591
|
}
|
|
1584
1592
|
if (result) {
|
|
1585
|
-
if (result.length + position
|
|
1586
|
-
makeRoom(result.length + position
|
|
1587
|
-
position
|
|
1593
|
+
if (result.length + position > safeEnd)
|
|
1594
|
+
makeRoom(result.length + position);
|
|
1595
|
+
position = writeExtensionData(result, target, position, extension.type);
|
|
1588
1596
|
}
|
|
1589
1597
|
return
|
|
1590
1598
|
}
|
|
@@ -1594,33 +1602,33 @@ class Packr extends Unpackr {
|
|
|
1594
1602
|
}
|
|
1595
1603
|
}
|
|
1596
1604
|
} else if (type === 'boolean') {
|
|
1597
|
-
target[position
|
|
1605
|
+
target[position++] = value ? 0xc3 : 0xc2;
|
|
1598
1606
|
} else if (type === 'bigint') {
|
|
1599
1607
|
if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
|
|
1600
1608
|
// use a signed int as long as it fits
|
|
1601
|
-
target[position
|
|
1602
|
-
targetView.setBigInt64(position
|
|
1609
|
+
target[position++] = 0xd3;
|
|
1610
|
+
targetView.setBigInt64(position, value);
|
|
1603
1611
|
} else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
|
|
1604
1612
|
// if we can fit an unsigned int, use that
|
|
1605
|
-
target[position
|
|
1606
|
-
targetView.setBigUint64(position
|
|
1613
|
+
target[position++] = 0xcf;
|
|
1614
|
+
targetView.setBigUint64(position, value);
|
|
1607
1615
|
} else {
|
|
1608
1616
|
// overflow
|
|
1609
1617
|
if (this.largeBigIntToFloat) {
|
|
1610
|
-
target[position
|
|
1611
|
-
targetView.setFloat64(position
|
|
1618
|
+
target[position++] = 0xcb;
|
|
1619
|
+
targetView.setFloat64(position, Number(value));
|
|
1612
1620
|
} else {
|
|
1613
1621
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
|
|
1614
1622
|
}
|
|
1615
1623
|
}
|
|
1616
|
-
position
|
|
1624
|
+
position += 8;
|
|
1617
1625
|
} else if (type === 'undefined') {
|
|
1618
1626
|
if (this.encodeUndefinedAsNil)
|
|
1619
|
-
target[position
|
|
1627
|
+
target[position++] = 0xc0;
|
|
1620
1628
|
else {
|
|
1621
|
-
target[position
|
|
1622
|
-
target[position
|
|
1623
|
-
target[position
|
|
1629
|
+
target[position++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
|
|
1630
|
+
target[position++] = 0;
|
|
1631
|
+
target[position++] = 0;
|
|
1624
1632
|
}
|
|
1625
1633
|
} else if (type === 'function') {
|
|
1626
1634
|
pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
|
|
@@ -1634,15 +1642,15 @@ class Packr extends Unpackr {
|
|
|
1634
1642
|
let keys = Object.keys(object);
|
|
1635
1643
|
let length = keys.length;
|
|
1636
1644
|
if (length < 0x10) {
|
|
1637
|
-
target[position
|
|
1645
|
+
target[position++] = 0x80 | length;
|
|
1638
1646
|
} else if (length < 0x10000) {
|
|
1639
|
-
target[position
|
|
1640
|
-
target[position
|
|
1641
|
-
target[position
|
|
1647
|
+
target[position++] = 0xde;
|
|
1648
|
+
target[position++] = length >> 8;
|
|
1649
|
+
target[position++] = length & 0xff;
|
|
1642
1650
|
} else {
|
|
1643
|
-
target[position
|
|
1644
|
-
targetView.setUint32(position
|
|
1645
|
-
position
|
|
1651
|
+
target[position++] = 0xdf;
|
|
1652
|
+
targetView.setUint32(position, length);
|
|
1653
|
+
position += 4;
|
|
1646
1654
|
}
|
|
1647
1655
|
let key;
|
|
1648
1656
|
for (let i = 0; i < length; i++) {
|
|
@@ -1651,9 +1659,9 @@ class Packr extends Unpackr {
|
|
|
1651
1659
|
}
|
|
1652
1660
|
} :
|
|
1653
1661
|
(object, safePrototype) => {
|
|
1654
|
-
target[position
|
|
1655
|
-
let objectOffset = position
|
|
1656
|
-
position
|
|
1662
|
+
target[position++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
|
|
1663
|
+
let objectOffset = position - start;
|
|
1664
|
+
position += 2;
|
|
1657
1665
|
let size = 0;
|
|
1658
1666
|
for (let key in object) {
|
|
1659
1667
|
if (safePrototype || object.hasOwnProperty(key)) {
|
|
@@ -1668,7 +1676,7 @@ class Packr extends Unpackr {
|
|
|
1668
1676
|
(options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
|
|
1669
1677
|
(object, safePrototype) => {
|
|
1670
1678
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
|
|
1671
|
-
let objectOffset = position
|
|
1679
|
+
let objectOffset = position++ - start;
|
|
1672
1680
|
let wroteKeys;
|
|
1673
1681
|
for (let key in object) {
|
|
1674
1682
|
if (safePrototype || object.hasOwnProperty(key)) {
|
|
@@ -1690,9 +1698,9 @@ class Packr extends Unpackr {
|
|
|
1690
1698
|
}
|
|
1691
1699
|
transition = nextTransition;
|
|
1692
1700
|
}
|
|
1693
|
-
if (objectOffset + start + 1 == position
|
|
1701
|
+
if (objectOffset + start + 1 == position) {
|
|
1694
1702
|
// first key, so we don't need to insert, we can just write record directly
|
|
1695
|
-
position
|
|
1703
|
+
position--;
|
|
1696
1704
|
newRecord(transition, keys, newTransitions);
|
|
1697
1705
|
} else // otherwise we need to insert the record, moving existing data after the record
|
|
1698
1706
|
insertNewRecord(transition, keys, objectOffset, newTransitions);
|
|
@@ -1724,10 +1732,10 @@ class Packr extends Unpackr {
|
|
|
1724
1732
|
let recordId = transition[RECORD_SYMBOL];
|
|
1725
1733
|
if (recordId) {
|
|
1726
1734
|
if (recordId >= 0x60 && useTwoByteRecords) {
|
|
1727
|
-
target[position
|
|
1728
|
-
target[position
|
|
1735
|
+
target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60;
|
|
1736
|
+
target[position++] = recordId >> 5;
|
|
1729
1737
|
} else
|
|
1730
|
-
target[position
|
|
1738
|
+
target[position++] = recordId;
|
|
1731
1739
|
} else {
|
|
1732
1740
|
newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
|
|
1733
1741
|
}
|
|
@@ -1747,13 +1755,13 @@ class Packr extends Unpackr {
|
|
|
1747
1755
|
} else // faster handling for smaller buffers
|
|
1748
1756
|
newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
|
|
1749
1757
|
let newBuffer = new ByteArrayAllocate(newSize);
|
|
1750
|
-
targetView = newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize);
|
|
1758
|
+
targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize));
|
|
1751
1759
|
end = Math.min(end, target.length);
|
|
1752
1760
|
if (target.copy)
|
|
1753
1761
|
target.copy(newBuffer, 0, start, end);
|
|
1754
1762
|
else
|
|
1755
1763
|
newBuffer.set(target.slice(start, end));
|
|
1756
|
-
position
|
|
1764
|
+
position -= start;
|
|
1757
1765
|
start = 0;
|
|
1758
1766
|
safeEnd = newBuffer.length - 10;
|
|
1759
1767
|
return target = newBuffer
|
|
@@ -1782,21 +1790,21 @@ class Packr extends Unpackr {
|
|
|
1782
1790
|
structures.sharedLength = recordId - 0x3f;
|
|
1783
1791
|
hasSharedUpdate = true;
|
|
1784
1792
|
if (highByte >= 0) {
|
|
1785
|
-
target[position
|
|
1786
|
-
target[position
|
|
1793
|
+
target[position++] = (recordId & 0x1f) + 0x60;
|
|
1794
|
+
target[position++] = highByte;
|
|
1787
1795
|
} else {
|
|
1788
|
-
target[position
|
|
1796
|
+
target[position++] = recordId;
|
|
1789
1797
|
}
|
|
1790
1798
|
} else {
|
|
1791
1799
|
if (highByte >= 0) {
|
|
1792
|
-
target[position
|
|
1793
|
-
target[position
|
|
1794
|
-
target[position
|
|
1795
|
-
target[position
|
|
1800
|
+
target[position++] = 0xd5; // fixext 2
|
|
1801
|
+
target[position++] = 0x72; // "r" record defintion extension type
|
|
1802
|
+
target[position++] = (recordId & 0x1f) + 0x60;
|
|
1803
|
+
target[position++] = highByte;
|
|
1796
1804
|
} else {
|
|
1797
|
-
target[position
|
|
1798
|
-
target[position
|
|
1799
|
-
target[position
|
|
1805
|
+
target[position++] = 0xd4; // fixext 1
|
|
1806
|
+
target[position++] = 0x72; // "r" record defintion extension type
|
|
1807
|
+
target[position++] = recordId;
|
|
1800
1808
|
}
|
|
1801
1809
|
|
|
1802
1810
|
if (newTransitions)
|
|
@@ -1810,57 +1818,57 @@ class Packr extends Unpackr {
|
|
|
1810
1818
|
};
|
|
1811
1819
|
const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
|
|
1812
1820
|
let mainTarget = target;
|
|
1813
|
-
let mainPosition = position
|
|
1821
|
+
let mainPosition = position;
|
|
1814
1822
|
let mainSafeEnd = safeEnd;
|
|
1815
1823
|
let mainStart = start;
|
|
1816
1824
|
target = keysTarget;
|
|
1817
|
-
position
|
|
1825
|
+
position = 0;
|
|
1818
1826
|
start = 0;
|
|
1819
1827
|
if (!target)
|
|
1820
1828
|
keysTarget = target = new ByteArrayAllocate(8192);
|
|
1821
1829
|
safeEnd = target.length - 10;
|
|
1822
1830
|
newRecord(transition, keys, newTransitions);
|
|
1823
1831
|
keysTarget = target;
|
|
1824
|
-
let keysPosition = position
|
|
1832
|
+
let keysPosition = position;
|
|
1825
1833
|
target = mainTarget;
|
|
1826
|
-
position
|
|
1834
|
+
position = mainPosition;
|
|
1827
1835
|
safeEnd = mainSafeEnd;
|
|
1828
1836
|
start = mainStart;
|
|
1829
1837
|
if (keysPosition > 1) {
|
|
1830
|
-
let newEnd = position
|
|
1838
|
+
let newEnd = position + keysPosition - 1;
|
|
1831
1839
|
if (newEnd > safeEnd)
|
|
1832
1840
|
makeRoom(newEnd);
|
|
1833
1841
|
let insertionPosition = insertionOffset + start;
|
|
1834
|
-
target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position
|
|
1842
|
+
target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position);
|
|
1835
1843
|
target.set(keysTarget.slice(0, keysPosition), insertionPosition);
|
|
1836
|
-
position
|
|
1844
|
+
position = newEnd;
|
|
1837
1845
|
} else {
|
|
1838
1846
|
target[insertionOffset + start] = keysTarget[0];
|
|
1839
1847
|
}
|
|
1840
1848
|
};
|
|
1841
1849
|
const writeStruct = (object, safePrototype) => {
|
|
1842
|
-
let newPosition = writeStructSlots(object, target, position
|
|
1850
|
+
let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
|
|
1843
1851
|
if (notifySharedUpdate)
|
|
1844
1852
|
return hasSharedUpdate = true;
|
|
1845
|
-
position
|
|
1853
|
+
position = newPosition;
|
|
1846
1854
|
if (start > 0) {
|
|
1847
1855
|
pack(value);
|
|
1848
1856
|
if (start == 0)
|
|
1849
|
-
return { position
|
|
1857
|
+
return { position, targetView, target }; // indicate the buffer was re-allocated
|
|
1850
1858
|
} else
|
|
1851
1859
|
pack(value);
|
|
1852
|
-
return position
|
|
1860
|
+
return position;
|
|
1853
1861
|
}, this);
|
|
1854
1862
|
if (newPosition === 0) // bail and go to a msgpack object
|
|
1855
1863
|
return writeObject(object, true);
|
|
1856
|
-
position
|
|
1864
|
+
position = newPosition;
|
|
1857
1865
|
};
|
|
1858
1866
|
}
|
|
1859
1867
|
useBuffer(buffer) {
|
|
1860
1868
|
// this means we are finished using our own buffer and we can write over it safely
|
|
1861
1869
|
target = buffer;
|
|
1862
1870
|
targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
|
|
1863
|
-
position
|
|
1871
|
+
position = 0;
|
|
1864
1872
|
}
|
|
1865
1873
|
clearSharedData() {
|
|
1866
1874
|
if (this.structures)
|
|
@@ -1943,7 +1951,7 @@ extensions = [{
|
|
|
1943
1951
|
if (this.moreTypes)
|
|
1944
1952
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1945
1953
|
else
|
|
1946
|
-
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
1954
|
+
writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
1947
1955
|
}
|
|
1948
1956
|
}, {
|
|
1949
1957
|
pack(typedArray, allocateForWrite) {
|
|
@@ -2065,17 +2073,17 @@ function insertIds(serialized, idsToInsert) {
|
|
|
2065
2073
|
}
|
|
2066
2074
|
|
|
2067
2075
|
function writeBundles(start, pack, incrementPosition) {
|
|
2068
|
-
if (bundledStrings
|
|
2069
|
-
targetView.setUint32(bundledStrings
|
|
2070
|
-
bundledStrings
|
|
2071
|
-
let writeStrings = bundledStrings
|
|
2072
|
-
bundledStrings
|
|
2076
|
+
if (bundledStrings.length > 0) {
|
|
2077
|
+
targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start);
|
|
2078
|
+
bundledStrings.stringsPosition = position - start;
|
|
2079
|
+
let writeStrings = bundledStrings;
|
|
2080
|
+
bundledStrings = null;
|
|
2073
2081
|
pack(writeStrings[0]);
|
|
2074
2082
|
pack(writeStrings[1]);
|
|
2075
2083
|
}
|
|
2076
2084
|
}
|
|
2077
2085
|
|
|
2078
|
-
function addExtension
|
|
2086
|
+
function addExtension(extension) {
|
|
2079
2087
|
if (extension.Class) {
|
|
2080
2088
|
if (!extension.pack && !extension.write)
|
|
2081
2089
|
throw new Error('Extension has no pack or write function')
|
|
@@ -2084,9 +2092,9 @@ function addExtension$1(extension) {
|
|
|
2084
2092
|
extensionClasses.unshift(extension.Class);
|
|
2085
2093
|
extensions.unshift(extension);
|
|
2086
2094
|
}
|
|
2087
|
-
addExtension(extension);
|
|
2095
|
+
addExtension$1(extension);
|
|
2088
2096
|
}
|
|
2089
|
-
function prepareStructures(structures, packr) {
|
|
2097
|
+
function prepareStructures$1(structures, packr) {
|
|
2090
2098
|
structures.isCompatible = (existingStructures) => {
|
|
2091
2099
|
let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
|
|
2092
2100
|
if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
|
|
@@ -2097,7 +2105,7 @@ function prepareStructures(structures, packr) {
|
|
|
2097
2105
|
}
|
|
2098
2106
|
function setWriteStructSlots(writeSlots, makeStructures) {
|
|
2099
2107
|
writeStructSlots = writeSlots;
|
|
2100
|
-
prepareStructures = makeStructures;
|
|
2108
|
+
prepareStructures$1 = makeStructures;
|
|
2101
2109
|
}
|
|
2102
2110
|
|
|
2103
2111
|
let defaultPackr = new Packr({ useRecords: false });
|
|
@@ -2125,18 +2133,18 @@ try {
|
|
|
2125
2133
|
}
|
|
2126
2134
|
|
|
2127
2135
|
let updatedPosition;
|
|
2128
|
-
const hasNodeBuffer
|
|
2129
|
-
let textEncoder
|
|
2136
|
+
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
|
2137
|
+
let textEncoder, currentSource;
|
|
2130
2138
|
try {
|
|
2131
|
-
textEncoder
|
|
2139
|
+
textEncoder = new TextEncoder();
|
|
2132
2140
|
} catch (error) {}
|
|
2133
|
-
const encodeUtf8 = hasNodeBuffer
|
|
2141
|
+
const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
|
|
2134
2142
|
return target.utf8Write(string, position, 0xffffffff)
|
|
2135
|
-
} : (textEncoder
|
|
2143
|
+
} : (textEncoder && textEncoder.encodeInto) ?
|
|
2136
2144
|
function(target, string, position) {
|
|
2137
|
-
return textEncoder
|
|
2145
|
+
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
2138
2146
|
} : false;
|
|
2139
|
-
setWriteStructSlots(writeStruct, prepareStructures
|
|
2147
|
+
setWriteStructSlots(writeStruct, prepareStructures);
|
|
2140
2148
|
function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
|
|
2141
2149
|
let typedStructs = packr.typedStructs || (packr.typedStructs = []);
|
|
2142
2150
|
// note that we rely on pack.js to load stored structures before we get to this point
|
|
@@ -2229,9 +2237,9 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
|
|
|
2229
2237
|
case 'string':
|
|
2230
2238
|
let strLength = value.length;
|
|
2231
2239
|
refOffset = refPosition - refsStartPosition;
|
|
2232
|
-
if ((strLength << 2) +
|
|
2240
|
+
if ((strLength << 2) + refPosition > safeEnd) {
|
|
2233
2241
|
let lastStart = start;
|
|
2234
|
-
target = makeRoom(refPosition);
|
|
2242
|
+
target = makeRoom((strLength << 2) + refPosition);
|
|
2235
2243
|
targetView = target.dataView;
|
|
2236
2244
|
position -= lastStart;
|
|
2237
2245
|
refsStartPosition -= lastStart;
|
|
@@ -2511,7 +2519,7 @@ function createTypeTransition(transition, type, size) {
|
|
|
2511
2519
|
newTransition.__parent = transition;
|
|
2512
2520
|
return newTransition;
|
|
2513
2521
|
}
|
|
2514
|
-
function onLoadedStructures
|
|
2522
|
+
function onLoadedStructures(sharedData) {
|
|
2515
2523
|
if (!(sharedData instanceof Map))
|
|
2516
2524
|
return sharedData;
|
|
2517
2525
|
let typed = sharedData.get('typed') || [];
|
|
@@ -2549,7 +2557,7 @@ function onLoadedStructures$1(sharedData) {
|
|
|
2549
2557
|
return named;
|
|
2550
2558
|
}
|
|
2551
2559
|
var sourceSymbol = Symbol.for('source');
|
|
2552
|
-
function readStruct
|
|
2560
|
+
function readStruct(src, position, srcEnd, unpackr) {
|
|
2553
2561
|
let recordId = src[position++] - 0x20;
|
|
2554
2562
|
if (recordId >= 24) {
|
|
2555
2563
|
switch(recordId) {
|
|
@@ -2820,14 +2828,14 @@ function withSource(get) {
|
|
|
2820
2828
|
}
|
|
2821
2829
|
}
|
|
2822
2830
|
|
|
2823
|
-
function saveState
|
|
2831
|
+
function saveState() {
|
|
2824
2832
|
if (currentSource) {
|
|
2825
2833
|
currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
|
|
2826
2834
|
currentSource.position = 0;
|
|
2827
2835
|
currentSource.bytesEnd = currentSource.bytes.length;
|
|
2828
2836
|
}
|
|
2829
2837
|
}
|
|
2830
|
-
function prepareStructures
|
|
2838
|
+
function prepareStructures(structures, packr) {
|
|
2831
2839
|
if (packr.typedStructs) {
|
|
2832
2840
|
let structMap = new Map();
|
|
2833
2841
|
structMap.set('named', structures);
|
|
@@ -2844,7 +2852,7 @@ function prepareStructures$1(structures, packr) {
|
|
|
2844
2852
|
let typed = existing.get('typed') || [];
|
|
2845
2853
|
if (typed.length !== lastTypedStructuresLength)
|
|
2846
2854
|
compatible = false;
|
|
2847
|
-
} else if (existing instanceof Array) {
|
|
2855
|
+
} else if (existing instanceof Array || Array.isArray(existing)) {
|
|
2848
2856
|
if (existing.length !== (packr.lastNamedStructuresLength || 0))
|
|
2849
2857
|
compatible = false;
|
|
2850
2858
|
}
|
|
@@ -2856,7 +2864,7 @@ function prepareStructures$1(structures, packr) {
|
|
|
2856
2864
|
return structures;
|
|
2857
2865
|
}
|
|
2858
2866
|
|
|
2859
|
-
setReadStruct(readStruct
|
|
2867
|
+
setReadStruct(readStruct, onLoadedStructures, saveState);
|
|
2860
2868
|
|
|
2861
2869
|
class PackrStream extends stream.Transform {
|
|
2862
2870
|
constructor(options) {
|
|
@@ -3029,7 +3037,7 @@ exports.Packr = Packr;
|
|
|
3029
3037
|
exports.PackrStream = PackrStream;
|
|
3030
3038
|
exports.Unpackr = Unpackr;
|
|
3031
3039
|
exports.UnpackrStream = UnpackrStream;
|
|
3032
|
-
exports.addExtension = addExtension
|
|
3040
|
+
exports.addExtension = addExtension;
|
|
3033
3041
|
exports.clearSource = clearSource;
|
|
3034
3042
|
exports.decode = decode;
|
|
3035
3043
|
exports.decodeIter = decodeIter;
|