msgpackr 1.7.1 → 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 +419 -382
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -83
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +450 -424
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +724 -510
- package/dist/test.js.map +1 -1
- package/index.d.ts +2 -0
- package/pack.js +41 -14
- package/package.json +7 -6
- package/rollup.config.js +32 -5
- package/struct.js +3 -3
- package/unpack.js +16 -14
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,19 +863,19 @@ 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
|
}
|
|
@@ -877,22 +885,22 @@ function readExt(length) {
|
|
|
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--;
|
|
890
|
-
return read()
|
|
897
|
+
position$1--;
|
|
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;
|
|
@@ -941,16 +949,7 @@ function readKey() {
|
|
|
941
949
|
|
|
942
950
|
// the registration of the record definition extension (as "r")
|
|
943
951
|
const recordDefinition = (id, highByte) => {
|
|
944
|
-
let structure;
|
|
945
|
-
if (currentUnpackr.freezeData) {
|
|
946
|
-
currentUnpackr.freezeData = false;
|
|
947
|
-
try {
|
|
948
|
-
structure = read();
|
|
949
|
-
} finally {
|
|
950
|
-
currentUnpackr.freezeData = true;
|
|
951
|
-
}
|
|
952
|
-
} else
|
|
953
|
-
structure = read();
|
|
952
|
+
let structure = read().map(property => property.toString()); // ensure that all keys are strings and that the array is mutable
|
|
954
953
|
let firstByte = id;
|
|
955
954
|
if (highByte !== undefined) {
|
|
956
955
|
id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
|
|
@@ -974,10 +973,10 @@ currentExtensions[0x65] = () => {
|
|
|
974
973
|
|
|
975
974
|
currentExtensions[0x69] = (data) => {
|
|
976
975
|
// id extension (for structured clones)
|
|
977
|
-
let id = dataView.getUint32(position - 4);
|
|
976
|
+
let id = dataView.getUint32(position$1 - 4);
|
|
978
977
|
if (!referenceMap)
|
|
979
978
|
referenceMap = new Map();
|
|
980
|
-
let token = src[position];
|
|
979
|
+
let token = src[position$1];
|
|
981
980
|
let target;
|
|
982
981
|
// TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
|
|
983
982
|
// ahead past references to record structure definitions
|
|
@@ -997,7 +996,7 @@ currentExtensions[0x69] = (data) => {
|
|
|
997
996
|
|
|
998
997
|
currentExtensions[0x70] = (data) => {
|
|
999
998
|
// pointer extension (for structured clones)
|
|
1000
|
-
let id = dataView.getUint32(position - 4);
|
|
999
|
+
let id = dataView.getUint32(position$1 - 4);
|
|
1001
1000
|
let refEntry = referenceMap.get(id);
|
|
1002
1001
|
refEntry.used = true;
|
|
1003
1002
|
return refEntry.target
|
|
@@ -1022,14 +1021,14 @@ currentExtensions[0x78] = () => {
|
|
|
1022
1021
|
const TEMP_BUNDLE = [];
|
|
1023
1022
|
currentExtensions[0x62] = (data) => {
|
|
1024
1023
|
let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
|
|
1025
|
-
let dataPosition = position;
|
|
1026
|
-
position += dataSize - data.length;
|
|
1027
|
-
bundledStrings = TEMP_BUNDLE;
|
|
1028
|
-
bundledStrings = [readOnlyJSString(), readOnlyJSString()];
|
|
1029
|
-
bundledStrings.position0 = 0;
|
|
1030
|
-
bundledStrings.position1 = 0;
|
|
1031
|
-
bundledStrings.postBundlePosition = position;
|
|
1032
|
-
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;
|
|
1033
1032
|
return read()
|
|
1034
1033
|
};
|
|
1035
1034
|
|
|
@@ -1051,18 +1050,18 @@ currentExtensions[0xff] = (data) => {
|
|
|
1051
1050
|
// registration of bulk record definition?
|
|
1052
1051
|
// currentExtensions[0x52] = () =>
|
|
1053
1052
|
|
|
1054
|
-
function saveState(callback) {
|
|
1053
|
+
function saveState$1(callback) {
|
|
1055
1054
|
if (onSaveState)
|
|
1056
1055
|
onSaveState();
|
|
1057
1056
|
let savedSrcEnd = srcEnd;
|
|
1058
|
-
let savedPosition = position;
|
|
1057
|
+
let savedPosition = position$1;
|
|
1059
1058
|
let savedStringPosition = stringPosition;
|
|
1060
1059
|
let savedSrcStringStart = srcStringStart;
|
|
1061
1060
|
let savedSrcStringEnd = srcStringEnd;
|
|
1062
1061
|
let savedSrcString = srcString;
|
|
1063
1062
|
let savedStrings = strings;
|
|
1064
1063
|
let savedReferenceMap = referenceMap;
|
|
1065
|
-
let savedBundledStrings = bundledStrings;
|
|
1064
|
+
let savedBundledStrings = bundledStrings$1;
|
|
1066
1065
|
|
|
1067
1066
|
// TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
|
|
1068
1067
|
let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
|
|
@@ -1072,14 +1071,14 @@ function saveState(callback) {
|
|
|
1072
1071
|
let savedSequentialMode = sequentialMode;
|
|
1073
1072
|
let value = callback();
|
|
1074
1073
|
srcEnd = savedSrcEnd;
|
|
1075
|
-
position = savedPosition;
|
|
1074
|
+
position$1 = savedPosition;
|
|
1076
1075
|
stringPosition = savedStringPosition;
|
|
1077
1076
|
srcStringStart = savedSrcStringStart;
|
|
1078
1077
|
srcStringEnd = savedSrcStringEnd;
|
|
1079
1078
|
srcString = savedSrcString;
|
|
1080
1079
|
strings = savedStrings;
|
|
1081
1080
|
referenceMap = savedReferenceMap;
|
|
1082
|
-
bundledStrings = savedBundledStrings;
|
|
1081
|
+
bundledStrings$1 = savedBundledStrings;
|
|
1083
1082
|
src = savedSrc;
|
|
1084
1083
|
sequentialMode = savedSequentialMode;
|
|
1085
1084
|
currentStructures = savedStructures;
|
|
@@ -1094,7 +1093,7 @@ function clearSource() {
|
|
|
1094
1093
|
currentStructures = null;
|
|
1095
1094
|
}
|
|
1096
1095
|
|
|
1097
|
-
function addExtension(extension) {
|
|
1096
|
+
function addExtension$1(extension) {
|
|
1098
1097
|
if (extension.unpack)
|
|
1099
1098
|
currentExtensions[extension.type] = extension.unpack;
|
|
1100
1099
|
else
|
|
@@ -1124,26 +1123,26 @@ function roundFloat32(float32Number) {
|
|
|
1124
1123
|
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
1125
1124
|
}
|
|
1126
1125
|
function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
|
|
1127
|
-
readStruct = updatedReadStruct;
|
|
1128
|
-
onLoadedStructures = loadedStructs;
|
|
1126
|
+
readStruct$1 = updatedReadStruct;
|
|
1127
|
+
onLoadedStructures$1 = loadedStructs;
|
|
1129
1128
|
onSaveState = saveState;
|
|
1130
1129
|
}
|
|
1131
1130
|
|
|
1132
|
-
let textEncoder;
|
|
1131
|
+
let textEncoder$1;
|
|
1133
1132
|
try {
|
|
1134
|
-
textEncoder = new TextEncoder();
|
|
1133
|
+
textEncoder$1 = new TextEncoder();
|
|
1135
1134
|
} catch (error) {}
|
|
1136
1135
|
let extensions, extensionClasses;
|
|
1137
|
-
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
|
1138
|
-
const ByteArrayAllocate = hasNodeBuffer ?
|
|
1136
|
+
const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
|
|
1137
|
+
const ByteArrayAllocate = hasNodeBuffer$1 ?
|
|
1139
1138
|
function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
|
|
1140
|
-
const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
|
|
1141
|
-
const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
|
|
1139
|
+
const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
|
|
1140
|
+
const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
|
|
1142
1141
|
let target, keysTarget;
|
|
1143
1142
|
let targetView;
|
|
1144
|
-
let position
|
|
1143
|
+
let position = 0;
|
|
1145
1144
|
let safeEnd;
|
|
1146
|
-
let bundledStrings
|
|
1145
|
+
let bundledStrings = null;
|
|
1147
1146
|
let writeStructSlots;
|
|
1148
1147
|
const MAX_BUNDLE_SIZE = 0xf000;
|
|
1149
1148
|
const hasNonLatin = /[\u0080-\uFFFF]/;
|
|
@@ -1158,9 +1157,9 @@ class Packr extends Unpackr {
|
|
|
1158
1157
|
let referenceMap;
|
|
1159
1158
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1160
1159
|
return target.utf8Write(string, position, 0xffffffff)
|
|
1161
|
-
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1160
|
+
} : (textEncoder$1 && textEncoder$1.encodeInto) ?
|
|
1162
1161
|
function(string, position) {
|
|
1163
|
-
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
1162
|
+
return textEncoder$1.encodeInto(string, target.subarray(position)).written
|
|
1164
1163
|
} : false;
|
|
1165
1164
|
|
|
1166
1165
|
let packr = this;
|
|
@@ -1195,25 +1194,25 @@ class Packr extends Unpackr {
|
|
|
1195
1194
|
this.pack = this.encode = function(value, encodeOptions) {
|
|
1196
1195
|
if (!target) {
|
|
1197
1196
|
target = new ByteArrayAllocate(8192);
|
|
1198
|
-
targetView = target.dataView = new DataView(target.buffer, 0, 8192);
|
|
1199
|
-
position
|
|
1197
|
+
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192));
|
|
1198
|
+
position = 0;
|
|
1200
1199
|
}
|
|
1201
1200
|
safeEnd = target.length - 10;
|
|
1202
|
-
if (safeEnd - position
|
|
1201
|
+
if (safeEnd - position < 0x800) {
|
|
1203
1202
|
// don't start too close to the end,
|
|
1204
1203
|
target = new ByteArrayAllocate(target.length);
|
|
1205
|
-
targetView = target.dataView = new DataView(target.buffer, 0, target.length);
|
|
1204
|
+
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
|
|
1206
1205
|
safeEnd = target.length - 10;
|
|
1207
|
-
position
|
|
1206
|
+
position = 0;
|
|
1208
1207
|
} else
|
|
1209
|
-
position
|
|
1210
|
-
start = position
|
|
1208
|
+
position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
|
|
1209
|
+
start = position;
|
|
1211
1210
|
referenceMap = packr.structuredClone ? new Map() : null;
|
|
1212
1211
|
if (packr.bundleStrings && typeof value !== 'string') {
|
|
1213
|
-
bundledStrings
|
|
1214
|
-
bundledStrings
|
|
1212
|
+
bundledStrings = [];
|
|
1213
|
+
bundledStrings.size = Infinity; // force a new bundle start on first string
|
|
1215
1214
|
} else
|
|
1216
|
-
bundledStrings
|
|
1215
|
+
bundledStrings = null;
|
|
1217
1216
|
structures = packr.structures;
|
|
1218
1217
|
if (structures) {
|
|
1219
1218
|
if (structures.uninitialized)
|
|
@@ -1254,27 +1253,51 @@ class Packr extends Unpackr {
|
|
|
1254
1253
|
writeStruct(value);
|
|
1255
1254
|
else
|
|
1256
1255
|
pack(value);
|
|
1256
|
+
let lastBundle = bundledStrings;
|
|
1257
|
+
if (bundledStrings)
|
|
1258
|
+
writeBundles(start, pack, 0);
|
|
1257
1259
|
if (referenceMap && referenceMap.idsToInsert) {
|
|
1258
|
-
let
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1260
|
+
let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
|
|
1261
|
+
let i = idsToInsert.length;
|
|
1262
|
+
let incrementPosition = -1;
|
|
1263
|
+
while (lastBundle && i > 0) {
|
|
1264
|
+
let insertionPoint = idsToInsert[--i].offset + start;
|
|
1265
|
+
if (insertionPoint < (lastBundle.stringsPosition + start) && incrementPosition === -1)
|
|
1266
|
+
incrementPosition = 0;
|
|
1267
|
+
if (insertionPoint > (lastBundle.position + start)) {
|
|
1268
|
+
if (incrementPosition >= 0)
|
|
1269
|
+
incrementPosition += 6;
|
|
1270
|
+
} else {
|
|
1271
|
+
if (incrementPosition >= 0) {
|
|
1272
|
+
// update the bundle reference now
|
|
1273
|
+
targetView.setUint32(lastBundle.position + start,
|
|
1274
|
+
targetView.getUint32(lastBundle.position + start) + incrementPosition);
|
|
1275
|
+
incrementPosition = -1; // reset
|
|
1276
|
+
}
|
|
1277
|
+
lastBundle = lastBundle.previous;
|
|
1278
|
+
i++;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
if (incrementPosition >= 0 && lastBundle) {
|
|
1282
|
+
// update the bundle reference now
|
|
1283
|
+
targetView.setUint32(lastBundle.position + start,
|
|
1284
|
+
targetView.getUint32(lastBundle.position + start) + incrementPosition);
|
|
1285
|
+
}
|
|
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);
|
|
1266
1291
|
referenceMap = null;
|
|
1267
1292
|
return serialized
|
|
1268
1293
|
}
|
|
1269
|
-
|
|
1270
|
-
writeBundles(start, pack, 0);
|
|
1271
|
-
packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1294
|
+
packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1272
1295
|
if (encodeOptions & REUSE_BUFFER_MODE) {
|
|
1273
1296
|
target.start = start;
|
|
1274
|
-
target.end = position
|
|
1297
|
+
target.end = position;
|
|
1275
1298
|
return target
|
|
1276
1299
|
}
|
|
1277
|
-
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
|
|
1278
1301
|
} finally {
|
|
1279
1302
|
if (structures) {
|
|
1280
1303
|
if (serializationsSinceTransitionRebuild < 10)
|
|
@@ -1297,8 +1320,8 @@ class Packr extends Unpackr {
|
|
|
1297
1320
|
}
|
|
1298
1321
|
if (hasSharedUpdate && packr.saveStructures) {
|
|
1299
1322
|
// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
1300
|
-
let returnBuffer = target.subarray(start, position
|
|
1301
|
-
let newSharedData = prepareStructures(structures, packr);
|
|
1323
|
+
let returnBuffer = target.subarray(start, position);
|
|
1324
|
+
let newSharedData = prepareStructures$1(structures, packr);
|
|
1302
1325
|
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
|
|
1303
1326
|
// get updated structures and try again if the update failed
|
|
1304
1327
|
return packr.pack(value)
|
|
@@ -1308,44 +1331,47 @@ class Packr extends Unpackr {
|
|
|
1308
1331
|
}
|
|
1309
1332
|
}
|
|
1310
1333
|
if (encodeOptions & RESET_BUFFER_MODE)
|
|
1311
|
-
position
|
|
1334
|
+
position = start;
|
|
1312
1335
|
}
|
|
1313
1336
|
};
|
|
1314
1337
|
const pack = (value) => {
|
|
1315
|
-
if (position
|
|
1316
|
-
target = makeRoom(position
|
|
1338
|
+
if (position > safeEnd)
|
|
1339
|
+
target = makeRoom(position);
|
|
1317
1340
|
|
|
1318
1341
|
var type = typeof value;
|
|
1319
1342
|
var length;
|
|
1320
1343
|
if (type === 'string') {
|
|
1321
1344
|
let strLength = value.length;
|
|
1322
|
-
if (bundledStrings
|
|
1323
|
-
if ((bundledStrings
|
|
1345
|
+
if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
|
|
1346
|
+
if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
|
|
1324
1347
|
let extStart;
|
|
1325
|
-
let maxBytes = (bundledStrings
|
|
1326
|
-
if (position
|
|
1327
|
-
target = makeRoom(position
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
target[position
|
|
1332
|
-
|
|
1333
|
-
position
|
|
1334
|
-
|
|
1335
|
-
|
|
1348
|
+
let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10;
|
|
1349
|
+
if (position + maxBytes > safeEnd)
|
|
1350
|
+
target = makeRoom(position + maxBytes);
|
|
1351
|
+
let lastBundle;
|
|
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
|
|
1359
|
+
writeBundles(start, pack, 0); // write the last bundles
|
|
1360
|
+
targetView.setUint16(extStart + start - 3, position - start - extStart);
|
|
1336
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)
|
|
1337
|
-
target[position
|
|
1338
|
-
target[position
|
|
1339
|
-
extStart = position
|
|
1340
|
-
position
|
|
1362
|
+
target[position++] = 0xd6; // fixext 4
|
|
1363
|
+
target[position++] = 0x62; // 'b'
|
|
1364
|
+
extStart = position - start;
|
|
1365
|
+
position += 4; // reserve for writing bundle reference
|
|
1341
1366
|
}
|
|
1342
|
-
bundledStrings
|
|
1343
|
-
bundledStrings
|
|
1344
|
-
bundledStrings
|
|
1367
|
+
bundledStrings = ['', '']; // create new ones
|
|
1368
|
+
bundledStrings.previous = lastBundle;
|
|
1369
|
+
bundledStrings.size = 0;
|
|
1370
|
+
bundledStrings.position = extStart;
|
|
1345
1371
|
}
|
|
1346
1372
|
let twoByte = hasNonLatin.test(value);
|
|
1347
|
-
bundledStrings
|
|
1348
|
-
target[position
|
|
1373
|
+
bundledStrings[twoByte ? 0 : 1] += value;
|
|
1374
|
+
target[position++] = 0xc1;
|
|
1349
1375
|
pack(twoByte ? -strLength : strLength);
|
|
1350
1376
|
return
|
|
1351
1377
|
}
|
|
@@ -1361,11 +1387,11 @@ class Packr extends Unpackr {
|
|
|
1361
1387
|
headerSize = 5;
|
|
1362
1388
|
}
|
|
1363
1389
|
let maxBytes = strLength * 3;
|
|
1364
|
-
if (position
|
|
1365
|
-
target = makeRoom(position
|
|
1390
|
+
if (position + maxBytes > safeEnd)
|
|
1391
|
+
target = makeRoom(position + maxBytes);
|
|
1366
1392
|
|
|
1367
1393
|
if (strLength < 0x40 || !encodeUtf8) {
|
|
1368
|
-
let i, c1, c2, strPosition = position
|
|
1394
|
+
let i, c1, c2, strPosition = position + headerSize;
|
|
1369
1395
|
for (i = 0; i < strLength; i++) {
|
|
1370
1396
|
c1 = value.charCodeAt(i);
|
|
1371
1397
|
if (c1 < 0x80) {
|
|
@@ -1389,88 +1415,88 @@ class Packr extends Unpackr {
|
|
|
1389
1415
|
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
1390
1416
|
}
|
|
1391
1417
|
}
|
|
1392
|
-
length = strPosition - position
|
|
1418
|
+
length = strPosition - position - headerSize;
|
|
1393
1419
|
} else {
|
|
1394
|
-
length = encodeUtf8(value, position
|
|
1420
|
+
length = encodeUtf8(value, position + headerSize);
|
|
1395
1421
|
}
|
|
1396
1422
|
|
|
1397
1423
|
if (length < 0x20) {
|
|
1398
|
-
target[position
|
|
1424
|
+
target[position++] = 0xa0 | length;
|
|
1399
1425
|
} else if (length < 0x100) {
|
|
1400
1426
|
if (headerSize < 2) {
|
|
1401
|
-
target.copyWithin(position
|
|
1427
|
+
target.copyWithin(position + 2, position + 1, position + 1 + length);
|
|
1402
1428
|
}
|
|
1403
|
-
target[position
|
|
1404
|
-
target[position
|
|
1429
|
+
target[position++] = 0xd9;
|
|
1430
|
+
target[position++] = length;
|
|
1405
1431
|
} else if (length < 0x10000) {
|
|
1406
1432
|
if (headerSize < 3) {
|
|
1407
|
-
target.copyWithin(position
|
|
1433
|
+
target.copyWithin(position + 3, position + 2, position + 2 + length);
|
|
1408
1434
|
}
|
|
1409
|
-
target[position
|
|
1410
|
-
target[position
|
|
1411
|
-
target[position
|
|
1435
|
+
target[position++] = 0xda;
|
|
1436
|
+
target[position++] = length >> 8;
|
|
1437
|
+
target[position++] = length & 0xff;
|
|
1412
1438
|
} else {
|
|
1413
1439
|
if (headerSize < 5) {
|
|
1414
|
-
target.copyWithin(position
|
|
1440
|
+
target.copyWithin(position + 5, position + 3, position + 3 + length);
|
|
1415
1441
|
}
|
|
1416
|
-
target[position
|
|
1417
|
-
targetView.setUint32(position
|
|
1418
|
-
position
|
|
1442
|
+
target[position++] = 0xdb;
|
|
1443
|
+
targetView.setUint32(position, length);
|
|
1444
|
+
position += 4;
|
|
1419
1445
|
}
|
|
1420
|
-
position
|
|
1446
|
+
position += length;
|
|
1421
1447
|
} else if (type === 'number') {
|
|
1422
1448
|
if (value >>> 0 === value) {// positive integer, 32-bit or less
|
|
1423
1449
|
// positive uint
|
|
1424
1450
|
if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
|
|
1425
|
-
target[position
|
|
1451
|
+
target[position++] = value;
|
|
1426
1452
|
} else if (value < 0x100) {
|
|
1427
|
-
target[position
|
|
1428
|
-
target[position
|
|
1453
|
+
target[position++] = 0xcc;
|
|
1454
|
+
target[position++] = value;
|
|
1429
1455
|
} else if (value < 0x10000) {
|
|
1430
|
-
target[position
|
|
1431
|
-
target[position
|
|
1432
|
-
target[position
|
|
1456
|
+
target[position++] = 0xcd;
|
|
1457
|
+
target[position++] = value >> 8;
|
|
1458
|
+
target[position++] = value & 0xff;
|
|
1433
1459
|
} else {
|
|
1434
|
-
target[position
|
|
1435
|
-
targetView.setUint32(position
|
|
1436
|
-
position
|
|
1460
|
+
target[position++] = 0xce;
|
|
1461
|
+
targetView.setUint32(position, value);
|
|
1462
|
+
position += 4;
|
|
1437
1463
|
}
|
|
1438
1464
|
} else if (value >> 0 === value) { // negative integer
|
|
1439
1465
|
if (value >= -0x20) {
|
|
1440
|
-
target[position
|
|
1466
|
+
target[position++] = 0x100 + value;
|
|
1441
1467
|
} else if (value >= -0x80) {
|
|
1442
|
-
target[position
|
|
1443
|
-
target[position
|
|
1468
|
+
target[position++] = 0xd0;
|
|
1469
|
+
target[position++] = value + 0x100;
|
|
1444
1470
|
} else if (value >= -0x8000) {
|
|
1445
|
-
target[position
|
|
1446
|
-
targetView.setInt16(position
|
|
1447
|
-
position
|
|
1471
|
+
target[position++] = 0xd1;
|
|
1472
|
+
targetView.setInt16(position, value);
|
|
1473
|
+
position += 2;
|
|
1448
1474
|
} else {
|
|
1449
|
-
target[position
|
|
1450
|
-
targetView.setInt32(position
|
|
1451
|
-
position
|
|
1475
|
+
target[position++] = 0xd2;
|
|
1476
|
+
targetView.setInt32(position, value);
|
|
1477
|
+
position += 4;
|
|
1452
1478
|
}
|
|
1453
1479
|
} else {
|
|
1454
1480
|
let useFloat32;
|
|
1455
1481
|
if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
|
|
1456
|
-
target[position
|
|
1457
|
-
targetView.setFloat32(position
|
|
1482
|
+
target[position++] = 0xca;
|
|
1483
|
+
targetView.setFloat32(position, value);
|
|
1458
1484
|
let xShifted;
|
|
1459
1485
|
if (useFloat32 < 4 ||
|
|
1460
1486
|
// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
1461
|
-
((xShifted = value * mult10[((target[position
|
|
1462
|
-
position
|
|
1487
|
+
((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
|
|
1488
|
+
position += 4;
|
|
1463
1489
|
return
|
|
1464
1490
|
} else
|
|
1465
|
-
position
|
|
1491
|
+
position--; // move back into position for writing a double
|
|
1466
1492
|
}
|
|
1467
|
-
target[position
|
|
1468
|
-
targetView.setFloat64(position
|
|
1469
|
-
position
|
|
1493
|
+
target[position++] = 0xcb;
|
|
1494
|
+
targetView.setFloat64(position, value);
|
|
1495
|
+
position += 8;
|
|
1470
1496
|
}
|
|
1471
1497
|
} else if (type === 'object') {
|
|
1472
1498
|
if (!value)
|
|
1473
|
-
target[position
|
|
1499
|
+
target[position++] = 0xc0;
|
|
1474
1500
|
else {
|
|
1475
1501
|
if (referenceMap) {
|
|
1476
1502
|
let referee = referenceMap.get(value);
|
|
@@ -1479,29 +1505,29 @@ class Packr extends Unpackr {
|
|
|
1479
1505
|
let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
|
|
1480
1506
|
referee.id = idsToInsert.push(referee);
|
|
1481
1507
|
}
|
|
1482
|
-
target[position
|
|
1483
|
-
target[position
|
|
1484
|
-
targetView.setUint32(position
|
|
1485
|
-
position
|
|
1508
|
+
target[position++] = 0xd6; // fixext 4
|
|
1509
|
+
target[position++] = 0x70; // "p" for pointer
|
|
1510
|
+
targetView.setUint32(position, referee.id);
|
|
1511
|
+
position += 4;
|
|
1486
1512
|
return
|
|
1487
1513
|
} else
|
|
1488
|
-
referenceMap.set(value, { offset: position
|
|
1514
|
+
referenceMap.set(value, { offset: position - start });
|
|
1489
1515
|
}
|
|
1490
1516
|
let constructor = value.constructor;
|
|
1491
1517
|
if (constructor === Object) {
|
|
1492
1518
|
writeObject(value, true);
|
|
1493
|
-
} else if (constructor === Array) {
|
|
1519
|
+
} else if (constructor === Array || Array.isArray(value)) {
|
|
1494
1520
|
length = value.length;
|
|
1495
1521
|
if (length < 0x10) {
|
|
1496
|
-
target[position
|
|
1522
|
+
target[position++] = 0x90 | length;
|
|
1497
1523
|
} else if (length < 0x10000) {
|
|
1498
|
-
target[position
|
|
1499
|
-
target[position
|
|
1500
|
-
target[position
|
|
1524
|
+
target[position++] = 0xdc;
|
|
1525
|
+
target[position++] = length >> 8;
|
|
1526
|
+
target[position++] = length & 0xff;
|
|
1501
1527
|
} else {
|
|
1502
|
-
target[position
|
|
1503
|
-
targetView.setUint32(position
|
|
1504
|
-
position
|
|
1528
|
+
target[position++] = 0xdd;
|
|
1529
|
+
targetView.setUint32(position, length);
|
|
1530
|
+
position += 4;
|
|
1505
1531
|
}
|
|
1506
1532
|
for (let i = 0; i < length; i++) {
|
|
1507
1533
|
pack(value[i]);
|
|
@@ -1509,15 +1535,15 @@ class Packr extends Unpackr {
|
|
|
1509
1535
|
} else if (constructor === Map) {
|
|
1510
1536
|
length = value.size;
|
|
1511
1537
|
if (length < 0x10) {
|
|
1512
|
-
target[position
|
|
1538
|
+
target[position++] = 0x80 | length;
|
|
1513
1539
|
} else if (length < 0x10000) {
|
|
1514
|
-
target[position
|
|
1515
|
-
target[position
|
|
1516
|
-
target[position
|
|
1540
|
+
target[position++] = 0xde;
|
|
1541
|
+
target[position++] = length >> 8;
|
|
1542
|
+
target[position++] = length & 0xff;
|
|
1517
1543
|
} else {
|
|
1518
|
-
target[position
|
|
1519
|
-
targetView.setUint32(position
|
|
1520
|
-
position
|
|
1544
|
+
target[position++] = 0xdf;
|
|
1545
|
+
targetView.setUint32(position, length);
|
|
1546
|
+
position += 4;
|
|
1521
1547
|
}
|
|
1522
1548
|
for (let [ key, entryValue ] of value) {
|
|
1523
1549
|
pack(key);
|
|
@@ -1530,16 +1556,16 @@ class Packr extends Unpackr {
|
|
|
1530
1556
|
let extension = extensions[i];
|
|
1531
1557
|
if (extension.write) {
|
|
1532
1558
|
if (extension.type) {
|
|
1533
|
-
target[position
|
|
1534
|
-
target[position
|
|
1535
|
-
target[position
|
|
1559
|
+
target[position++] = 0xd4; // one byte "tag" extension
|
|
1560
|
+
target[position++] = extension.type;
|
|
1561
|
+
target[position++] = 0;
|
|
1536
1562
|
}
|
|
1537
1563
|
pack(extension.write.call(this, value));
|
|
1538
1564
|
return
|
|
1539
1565
|
}
|
|
1540
1566
|
let currentTarget = target;
|
|
1541
1567
|
let currentTargetView = targetView;
|
|
1542
|
-
let currentPosition = position
|
|
1568
|
+
let currentPosition = position;
|
|
1543
1569
|
target = null;
|
|
1544
1570
|
let result;
|
|
1545
1571
|
try {
|
|
@@ -1547,11 +1573,11 @@ class Packr extends Unpackr {
|
|
|
1547
1573
|
// restore target and use it
|
|
1548
1574
|
target = currentTarget;
|
|
1549
1575
|
currentTarget = null;
|
|
1550
|
-
position
|
|
1551
|
-
if (position
|
|
1552
|
-
makeRoom(position
|
|
1576
|
+
position += size;
|
|
1577
|
+
if (position > safeEnd)
|
|
1578
|
+
makeRoom(position);
|
|
1553
1579
|
return {
|
|
1554
|
-
target, targetView, position: position
|
|
1580
|
+
target, targetView, position: position - size
|
|
1555
1581
|
}
|
|
1556
1582
|
}, pack);
|
|
1557
1583
|
} finally {
|
|
@@ -1559,14 +1585,14 @@ class Packr extends Unpackr {
|
|
|
1559
1585
|
if (currentTarget) {
|
|
1560
1586
|
target = currentTarget;
|
|
1561
1587
|
targetView = currentTargetView;
|
|
1562
|
-
position
|
|
1588
|
+
position = currentPosition;
|
|
1563
1589
|
safeEnd = target.length - 10;
|
|
1564
1590
|
}
|
|
1565
1591
|
}
|
|
1566
1592
|
if (result) {
|
|
1567
|
-
if (result.length + position
|
|
1568
|
-
makeRoom(result.length + position
|
|
1569
|
-
position
|
|
1593
|
+
if (result.length + position > safeEnd)
|
|
1594
|
+
makeRoom(result.length + position);
|
|
1595
|
+
position = writeExtensionData(result, target, position, extension.type);
|
|
1570
1596
|
}
|
|
1571
1597
|
return
|
|
1572
1598
|
}
|
|
@@ -1576,33 +1602,33 @@ class Packr extends Unpackr {
|
|
|
1576
1602
|
}
|
|
1577
1603
|
}
|
|
1578
1604
|
} else if (type === 'boolean') {
|
|
1579
|
-
target[position
|
|
1605
|
+
target[position++] = value ? 0xc3 : 0xc2;
|
|
1580
1606
|
} else if (type === 'bigint') {
|
|
1581
1607
|
if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
|
|
1582
1608
|
// use a signed int as long as it fits
|
|
1583
|
-
target[position
|
|
1584
|
-
targetView.setBigInt64(position
|
|
1609
|
+
target[position++] = 0xd3;
|
|
1610
|
+
targetView.setBigInt64(position, value);
|
|
1585
1611
|
} else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
|
|
1586
1612
|
// if we can fit an unsigned int, use that
|
|
1587
|
-
target[position
|
|
1588
|
-
targetView.setBigUint64(position
|
|
1613
|
+
target[position++] = 0xcf;
|
|
1614
|
+
targetView.setBigUint64(position, value);
|
|
1589
1615
|
} else {
|
|
1590
1616
|
// overflow
|
|
1591
1617
|
if (this.largeBigIntToFloat) {
|
|
1592
|
-
target[position
|
|
1593
|
-
targetView.setFloat64(position
|
|
1618
|
+
target[position++] = 0xcb;
|
|
1619
|
+
targetView.setFloat64(position, Number(value));
|
|
1594
1620
|
} else {
|
|
1595
1621
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
|
|
1596
1622
|
}
|
|
1597
1623
|
}
|
|
1598
|
-
position
|
|
1624
|
+
position += 8;
|
|
1599
1625
|
} else if (type === 'undefined') {
|
|
1600
1626
|
if (this.encodeUndefinedAsNil)
|
|
1601
|
-
target[position
|
|
1627
|
+
target[position++] = 0xc0;
|
|
1602
1628
|
else {
|
|
1603
|
-
target[position
|
|
1604
|
-
target[position
|
|
1605
|
-
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;
|
|
1606
1632
|
}
|
|
1607
1633
|
} else if (type === 'function') {
|
|
1608
1634
|
pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
|
|
@@ -1616,15 +1642,15 @@ class Packr extends Unpackr {
|
|
|
1616
1642
|
let keys = Object.keys(object);
|
|
1617
1643
|
let length = keys.length;
|
|
1618
1644
|
if (length < 0x10) {
|
|
1619
|
-
target[position
|
|
1645
|
+
target[position++] = 0x80 | length;
|
|
1620
1646
|
} else if (length < 0x10000) {
|
|
1621
|
-
target[position
|
|
1622
|
-
target[position
|
|
1623
|
-
target[position
|
|
1647
|
+
target[position++] = 0xde;
|
|
1648
|
+
target[position++] = length >> 8;
|
|
1649
|
+
target[position++] = length & 0xff;
|
|
1624
1650
|
} else {
|
|
1625
|
-
target[position
|
|
1626
|
-
targetView.setUint32(position
|
|
1627
|
-
position
|
|
1651
|
+
target[position++] = 0xdf;
|
|
1652
|
+
targetView.setUint32(position, length);
|
|
1653
|
+
position += 4;
|
|
1628
1654
|
}
|
|
1629
1655
|
let key;
|
|
1630
1656
|
for (let i = 0; i < length; i++) {
|
|
@@ -1633,9 +1659,9 @@ class Packr extends Unpackr {
|
|
|
1633
1659
|
}
|
|
1634
1660
|
} :
|
|
1635
1661
|
(object, safePrototype) => {
|
|
1636
|
-
target[position
|
|
1637
|
-
let objectOffset = position
|
|
1638
|
-
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;
|
|
1639
1665
|
let size = 0;
|
|
1640
1666
|
for (let key in object) {
|
|
1641
1667
|
if (safePrototype || object.hasOwnProperty(key)) {
|
|
@@ -1650,7 +1676,7 @@ class Packr extends Unpackr {
|
|
|
1650
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)
|
|
1651
1677
|
(object, safePrototype) => {
|
|
1652
1678
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
|
|
1653
|
-
let objectOffset = position
|
|
1679
|
+
let objectOffset = position++ - start;
|
|
1654
1680
|
let wroteKeys;
|
|
1655
1681
|
for (let key in object) {
|
|
1656
1682
|
if (safePrototype || object.hasOwnProperty(key)) {
|
|
@@ -1672,9 +1698,9 @@ class Packr extends Unpackr {
|
|
|
1672
1698
|
}
|
|
1673
1699
|
transition = nextTransition;
|
|
1674
1700
|
}
|
|
1675
|
-
if (objectOffset + start + 1 == position
|
|
1701
|
+
if (objectOffset + start + 1 == position) {
|
|
1676
1702
|
// first key, so we don't need to insert, we can just write record directly
|
|
1677
|
-
position
|
|
1703
|
+
position--;
|
|
1678
1704
|
newRecord(transition, keys, newTransitions);
|
|
1679
1705
|
} else // otherwise we need to insert the record, moving existing data after the record
|
|
1680
1706
|
insertNewRecord(transition, keys, objectOffset, newTransitions);
|
|
@@ -1706,10 +1732,10 @@ class Packr extends Unpackr {
|
|
|
1706
1732
|
let recordId = transition[RECORD_SYMBOL];
|
|
1707
1733
|
if (recordId) {
|
|
1708
1734
|
if (recordId >= 0x60 && useTwoByteRecords) {
|
|
1709
|
-
target[position
|
|
1710
|
-
target[position
|
|
1735
|
+
target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60;
|
|
1736
|
+
target[position++] = recordId >> 5;
|
|
1711
1737
|
} else
|
|
1712
|
-
target[position
|
|
1738
|
+
target[position++] = recordId;
|
|
1713
1739
|
} else {
|
|
1714
1740
|
newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
|
|
1715
1741
|
}
|
|
@@ -1729,13 +1755,13 @@ class Packr extends Unpackr {
|
|
|
1729
1755
|
} else // faster handling for smaller buffers
|
|
1730
1756
|
newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
|
|
1731
1757
|
let newBuffer = new ByteArrayAllocate(newSize);
|
|
1732
|
-
targetView = newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize);
|
|
1758
|
+
targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize));
|
|
1733
1759
|
end = Math.min(end, target.length);
|
|
1734
1760
|
if (target.copy)
|
|
1735
1761
|
target.copy(newBuffer, 0, start, end);
|
|
1736
1762
|
else
|
|
1737
1763
|
newBuffer.set(target.slice(start, end));
|
|
1738
|
-
position
|
|
1764
|
+
position -= start;
|
|
1739
1765
|
start = 0;
|
|
1740
1766
|
safeEnd = newBuffer.length - 10;
|
|
1741
1767
|
return target = newBuffer
|
|
@@ -1764,21 +1790,21 @@ class Packr extends Unpackr {
|
|
|
1764
1790
|
structures.sharedLength = recordId - 0x3f;
|
|
1765
1791
|
hasSharedUpdate = true;
|
|
1766
1792
|
if (highByte >= 0) {
|
|
1767
|
-
target[position
|
|
1768
|
-
target[position
|
|
1793
|
+
target[position++] = (recordId & 0x1f) + 0x60;
|
|
1794
|
+
target[position++] = highByte;
|
|
1769
1795
|
} else {
|
|
1770
|
-
target[position
|
|
1796
|
+
target[position++] = recordId;
|
|
1771
1797
|
}
|
|
1772
1798
|
} else {
|
|
1773
1799
|
if (highByte >= 0) {
|
|
1774
|
-
target[position
|
|
1775
|
-
target[position
|
|
1776
|
-
target[position
|
|
1777
|
-
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;
|
|
1778
1804
|
} else {
|
|
1779
|
-
target[position
|
|
1780
|
-
target[position
|
|
1781
|
-
target[position
|
|
1805
|
+
target[position++] = 0xd4; // fixext 1
|
|
1806
|
+
target[position++] = 0x72; // "r" record defintion extension type
|
|
1807
|
+
target[position++] = recordId;
|
|
1782
1808
|
}
|
|
1783
1809
|
|
|
1784
1810
|
if (newTransitions)
|
|
@@ -1792,57 +1818,57 @@ class Packr extends Unpackr {
|
|
|
1792
1818
|
};
|
|
1793
1819
|
const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
|
|
1794
1820
|
let mainTarget = target;
|
|
1795
|
-
let mainPosition = position
|
|
1821
|
+
let mainPosition = position;
|
|
1796
1822
|
let mainSafeEnd = safeEnd;
|
|
1797
1823
|
let mainStart = start;
|
|
1798
1824
|
target = keysTarget;
|
|
1799
|
-
position
|
|
1825
|
+
position = 0;
|
|
1800
1826
|
start = 0;
|
|
1801
1827
|
if (!target)
|
|
1802
1828
|
keysTarget = target = new ByteArrayAllocate(8192);
|
|
1803
1829
|
safeEnd = target.length - 10;
|
|
1804
1830
|
newRecord(transition, keys, newTransitions);
|
|
1805
1831
|
keysTarget = target;
|
|
1806
|
-
let keysPosition = position
|
|
1832
|
+
let keysPosition = position;
|
|
1807
1833
|
target = mainTarget;
|
|
1808
|
-
position
|
|
1834
|
+
position = mainPosition;
|
|
1809
1835
|
safeEnd = mainSafeEnd;
|
|
1810
1836
|
start = mainStart;
|
|
1811
1837
|
if (keysPosition > 1) {
|
|
1812
|
-
let newEnd = position
|
|
1838
|
+
let newEnd = position + keysPosition - 1;
|
|
1813
1839
|
if (newEnd > safeEnd)
|
|
1814
1840
|
makeRoom(newEnd);
|
|
1815
1841
|
let insertionPosition = insertionOffset + start;
|
|
1816
|
-
target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position
|
|
1842
|
+
target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position);
|
|
1817
1843
|
target.set(keysTarget.slice(0, keysPosition), insertionPosition);
|
|
1818
|
-
position
|
|
1844
|
+
position = newEnd;
|
|
1819
1845
|
} else {
|
|
1820
1846
|
target[insertionOffset + start] = keysTarget[0];
|
|
1821
1847
|
}
|
|
1822
1848
|
};
|
|
1823
1849
|
const writeStruct = (object, safePrototype) => {
|
|
1824
|
-
let newPosition = writeStructSlots(object, target, position
|
|
1850
|
+
let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
|
|
1825
1851
|
if (notifySharedUpdate)
|
|
1826
1852
|
return hasSharedUpdate = true;
|
|
1827
|
-
position
|
|
1853
|
+
position = newPosition;
|
|
1828
1854
|
if (start > 0) {
|
|
1829
1855
|
pack(value);
|
|
1830
1856
|
if (start == 0)
|
|
1831
|
-
return { position
|
|
1857
|
+
return { position, targetView, target }; // indicate the buffer was re-allocated
|
|
1832
1858
|
} else
|
|
1833
1859
|
pack(value);
|
|
1834
|
-
return position
|
|
1860
|
+
return position;
|
|
1835
1861
|
}, this);
|
|
1836
1862
|
if (newPosition === 0) // bail and go to a msgpack object
|
|
1837
1863
|
return writeObject(object, true);
|
|
1838
|
-
position
|
|
1864
|
+
position = newPosition;
|
|
1839
1865
|
};
|
|
1840
1866
|
}
|
|
1841
1867
|
useBuffer(buffer) {
|
|
1842
1868
|
// this means we are finished using our own buffer and we can write over it safely
|
|
1843
1869
|
target = buffer;
|
|
1844
1870
|
targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
|
|
1845
|
-
position
|
|
1871
|
+
position = 0;
|
|
1846
1872
|
}
|
|
1847
1873
|
clearSharedData() {
|
|
1848
1874
|
if (this.structures)
|
|
@@ -1925,7 +1951,7 @@ extensions = [{
|
|
|
1925
1951
|
if (this.moreTypes)
|
|
1926
1952
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1927
1953
|
else
|
|
1928
|
-
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
1954
|
+
writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
1929
1955
|
}
|
|
1930
1956
|
}, {
|
|
1931
1957
|
pack(typedArray, allocateForWrite) {
|
|
@@ -2029,7 +2055,6 @@ function insertIds(serialized, idsToInsert) {
|
|
|
2029
2055
|
let nextId;
|
|
2030
2056
|
let distanceToMove = idsToInsert.length * 6;
|
|
2031
2057
|
let lastEnd = serialized.length - distanceToMove;
|
|
2032
|
-
idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
|
|
2033
2058
|
while (nextId = idsToInsert.pop()) {
|
|
2034
2059
|
let offset = nextId.offset;
|
|
2035
2060
|
let id = nextId.id;
|
|
@@ -2048,16 +2073,17 @@ function insertIds(serialized, idsToInsert) {
|
|
|
2048
2073
|
}
|
|
2049
2074
|
|
|
2050
2075
|
function writeBundles(start, pack, incrementPosition) {
|
|
2051
|
-
if (bundledStrings
|
|
2052
|
-
targetView.setUint32(bundledStrings
|
|
2053
|
-
|
|
2054
|
-
|
|
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;
|
|
2055
2081
|
pack(writeStrings[0]);
|
|
2056
2082
|
pack(writeStrings[1]);
|
|
2057
2083
|
}
|
|
2058
2084
|
}
|
|
2059
2085
|
|
|
2060
|
-
function addExtension
|
|
2086
|
+
function addExtension(extension) {
|
|
2061
2087
|
if (extension.Class) {
|
|
2062
2088
|
if (!extension.pack && !extension.write)
|
|
2063
2089
|
throw new Error('Extension has no pack or write function')
|
|
@@ -2066,9 +2092,9 @@ function addExtension$1(extension) {
|
|
|
2066
2092
|
extensionClasses.unshift(extension.Class);
|
|
2067
2093
|
extensions.unshift(extension);
|
|
2068
2094
|
}
|
|
2069
|
-
addExtension(extension);
|
|
2095
|
+
addExtension$1(extension);
|
|
2070
2096
|
}
|
|
2071
|
-
function prepareStructures(structures, packr) {
|
|
2097
|
+
function prepareStructures$1(structures, packr) {
|
|
2072
2098
|
structures.isCompatible = (existingStructures) => {
|
|
2073
2099
|
let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
|
|
2074
2100
|
if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
|
|
@@ -2079,7 +2105,7 @@ function prepareStructures(structures, packr) {
|
|
|
2079
2105
|
}
|
|
2080
2106
|
function setWriteStructSlots(writeSlots, makeStructures) {
|
|
2081
2107
|
writeStructSlots = writeSlots;
|
|
2082
|
-
prepareStructures = makeStructures;
|
|
2108
|
+
prepareStructures$1 = makeStructures;
|
|
2083
2109
|
}
|
|
2084
2110
|
|
|
2085
2111
|
let defaultPackr = new Packr({ useRecords: false });
|
|
@@ -2107,18 +2133,18 @@ try {
|
|
|
2107
2133
|
}
|
|
2108
2134
|
|
|
2109
2135
|
let updatedPosition;
|
|
2110
|
-
const hasNodeBuffer
|
|
2111
|
-
let textEncoder
|
|
2136
|
+
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
|
2137
|
+
let textEncoder, currentSource;
|
|
2112
2138
|
try {
|
|
2113
|
-
textEncoder
|
|
2139
|
+
textEncoder = new TextEncoder();
|
|
2114
2140
|
} catch (error) {}
|
|
2115
|
-
const encodeUtf8 = hasNodeBuffer
|
|
2141
|
+
const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
|
|
2116
2142
|
return target.utf8Write(string, position, 0xffffffff)
|
|
2117
|
-
} : (textEncoder
|
|
2143
|
+
} : (textEncoder && textEncoder.encodeInto) ?
|
|
2118
2144
|
function(target, string, position) {
|
|
2119
|
-
return textEncoder
|
|
2145
|
+
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
2120
2146
|
} : false;
|
|
2121
|
-
setWriteStructSlots(writeStruct, prepareStructures
|
|
2147
|
+
setWriteStructSlots(writeStruct, prepareStructures);
|
|
2122
2148
|
function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
|
|
2123
2149
|
let typedStructs = packr.typedStructs || (packr.typedStructs = []);
|
|
2124
2150
|
// note that we rely on pack.js to load stored structures before we get to this point
|
|
@@ -2211,9 +2237,9 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
|
|
|
2211
2237
|
case 'string':
|
|
2212
2238
|
let strLength = value.length;
|
|
2213
2239
|
refOffset = refPosition - refsStartPosition;
|
|
2214
|
-
if ((strLength << 2) +
|
|
2240
|
+
if ((strLength << 2) + refPosition > safeEnd) {
|
|
2215
2241
|
let lastStart = start;
|
|
2216
|
-
target = makeRoom(refPosition);
|
|
2242
|
+
target = makeRoom((strLength << 2) + refPosition);
|
|
2217
2243
|
targetView = target.dataView;
|
|
2218
2244
|
position -= lastStart;
|
|
2219
2245
|
refsStartPosition -= lastStart;
|
|
@@ -2493,7 +2519,7 @@ function createTypeTransition(transition, type, size) {
|
|
|
2493
2519
|
newTransition.__parent = transition;
|
|
2494
2520
|
return newTransition;
|
|
2495
2521
|
}
|
|
2496
|
-
function onLoadedStructures
|
|
2522
|
+
function onLoadedStructures(sharedData) {
|
|
2497
2523
|
if (!(sharedData instanceof Map))
|
|
2498
2524
|
return sharedData;
|
|
2499
2525
|
let typed = sharedData.get('typed') || [];
|
|
@@ -2531,7 +2557,7 @@ function onLoadedStructures$1(sharedData) {
|
|
|
2531
2557
|
return named;
|
|
2532
2558
|
}
|
|
2533
2559
|
var sourceSymbol = Symbol.for('source');
|
|
2534
|
-
function readStruct
|
|
2560
|
+
function readStruct(src, position, srcEnd, unpackr) {
|
|
2535
2561
|
let recordId = src[position++] - 0x20;
|
|
2536
2562
|
if (recordId >= 24) {
|
|
2537
2563
|
switch(recordId) {
|
|
@@ -2802,14 +2828,14 @@ function withSource(get) {
|
|
|
2802
2828
|
}
|
|
2803
2829
|
}
|
|
2804
2830
|
|
|
2805
|
-
function saveState
|
|
2831
|
+
function saveState() {
|
|
2806
2832
|
if (currentSource) {
|
|
2807
2833
|
currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
|
|
2808
2834
|
currentSource.position = 0;
|
|
2809
2835
|
currentSource.bytesEnd = currentSource.bytes.length;
|
|
2810
2836
|
}
|
|
2811
2837
|
}
|
|
2812
|
-
function prepareStructures
|
|
2838
|
+
function prepareStructures(structures, packr) {
|
|
2813
2839
|
if (packr.typedStructs) {
|
|
2814
2840
|
let structMap = new Map();
|
|
2815
2841
|
structMap.set('named', structures);
|
|
@@ -2826,7 +2852,7 @@ function prepareStructures$1(structures, packr) {
|
|
|
2826
2852
|
let typed = existing.get('typed') || [];
|
|
2827
2853
|
if (typed.length !== lastTypedStructuresLength)
|
|
2828
2854
|
compatible = false;
|
|
2829
|
-
} else if (existing instanceof Array) {
|
|
2855
|
+
} else if (existing instanceof Array || Array.isArray(existing)) {
|
|
2830
2856
|
if (existing.length !== (packr.lastNamedStructuresLength || 0))
|
|
2831
2857
|
compatible = false;
|
|
2832
2858
|
}
|
|
@@ -2838,7 +2864,7 @@ function prepareStructures$1(structures, packr) {
|
|
|
2838
2864
|
return structures;
|
|
2839
2865
|
}
|
|
2840
2866
|
|
|
2841
|
-
setReadStruct(readStruct
|
|
2867
|
+
setReadStruct(readStruct, onLoadedStructures, saveState);
|
|
2842
2868
|
|
|
2843
2869
|
class PackrStream extends stream.Transform {
|
|
2844
2870
|
constructor(options) {
|
|
@@ -3011,7 +3037,7 @@ exports.Packr = Packr;
|
|
|
3011
3037
|
exports.PackrStream = PackrStream;
|
|
3012
3038
|
exports.Unpackr = Unpackr;
|
|
3013
3039
|
exports.UnpackrStream = UnpackrStream;
|
|
3014
|
-
exports.addExtension = addExtension
|
|
3040
|
+
exports.addExtension = addExtension;
|
|
3015
3041
|
exports.clearSource = clearSource;
|
|
3016
3042
|
exports.decode = decode;
|
|
3017
3043
|
exports.decodeIter = decodeIter;
|