msgpackr 1.11.12 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/index-no-eval.cjs +209 -245
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +209 -245
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +232 -1064
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +246 -1137
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +167 -186
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.js +5 -5
- package/iterators.js +28 -28
- package/node-index.js +12 -13
- package/pack.js +580 -611
- package/package.json +1 -1
- package/stream.js +31 -31
- package/unpack.js +612 -630
- package/struct.js +0 -815
package/dist/index-no-eval.cjs
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
C1.name = 'MessagePack 0xC1';
|
|
30
30
|
var sequentialMode = false;
|
|
31
31
|
var inlineObjectReadThreshold = 2;
|
|
32
|
-
var readStruct;
|
|
33
32
|
var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
|
|
34
33
|
|
|
35
34
|
class Unpackr {
|
|
@@ -62,8 +61,8 @@
|
|
|
62
61
|
// re-entrant execution, save the state and restore it after we do this unpack
|
|
63
62
|
return saveState(() => {
|
|
64
63
|
clearSource();
|
|
65
|
-
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
|
|
66
|
-
})
|
|
64
|
+
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
|
|
65
|
+
});
|
|
67
66
|
}
|
|
68
67
|
if (!source.buffer && source.constructor === ArrayBuffer)
|
|
69
68
|
source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
|
|
@@ -87,14 +86,14 @@
|
|
|
87
86
|
// if it doesn't have a buffer, maybe it is the wrong type of object
|
|
88
87
|
src = null;
|
|
89
88
|
if (source instanceof Uint8Array)
|
|
90
|
-
throw error
|
|
91
|
-
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
|
|
89
|
+
throw error;
|
|
90
|
+
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
|
|
92
91
|
}
|
|
93
92
|
if (this instanceof Unpackr) {
|
|
94
93
|
currentUnpackr = this;
|
|
95
94
|
if (this.structures) {
|
|
96
95
|
currentStructures = this.structures;
|
|
97
|
-
return checkedRead(
|
|
96
|
+
return checkedRead();
|
|
98
97
|
} else if (!currentStructures || currentStructures.length > 0) {
|
|
99
98
|
currentStructures = [];
|
|
100
99
|
}
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
if (!currentStructures || currentStructures.length > 0)
|
|
104
103
|
currentStructures = [];
|
|
105
104
|
}
|
|
106
|
-
return checkedRead(
|
|
105
|
+
return checkedRead();
|
|
107
106
|
}
|
|
108
107
|
unpackMultiple(source, forEach) {
|
|
109
108
|
let values, lastPosition = 0;
|
|
@@ -116,7 +115,7 @@
|
|
|
116
115
|
while(position$1 < size) {
|
|
117
116
|
lastPosition = position$1;
|
|
118
117
|
if (forEach(checkedRead(), lastPosition, position$1) === false) {
|
|
119
|
-
return
|
|
118
|
+
return;
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
}
|
|
@@ -126,12 +125,12 @@
|
|
|
126
125
|
lastPosition = position$1;
|
|
127
126
|
values.push(checkedRead());
|
|
128
127
|
}
|
|
129
|
-
return values
|
|
128
|
+
return values;
|
|
130
129
|
}
|
|
131
130
|
} catch(error) {
|
|
132
131
|
error.lastPosition = lastPosition;
|
|
133
132
|
error.values = values;
|
|
134
|
-
throw error
|
|
133
|
+
throw error;
|
|
135
134
|
} finally {
|
|
136
135
|
sequentialMode = false;
|
|
137
136
|
clearSource();
|
|
@@ -161,10 +160,10 @@
|
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
}
|
|
164
|
-
return this.structures = loadedStructures
|
|
163
|
+
return this.structures = loadedStructures;
|
|
165
164
|
}
|
|
166
165
|
decode(source, options) {
|
|
167
|
-
return this.unpack(source, options)
|
|
166
|
+
return this.unpack(source, options);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
function checkedRead(options) {
|
|
@@ -174,15 +173,7 @@
|
|
|
174
173
|
if (sharedLength < currentStructures.length)
|
|
175
174
|
currentStructures.length = sharedLength;
|
|
176
175
|
}
|
|
177
|
-
let result;
|
|
178
|
-
if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct) {
|
|
179
|
-
result = readStruct(src, position$1, srcEnd, currentUnpackr);
|
|
180
|
-
src = null; // dispose of this so that recursive unpack calls don't save state
|
|
181
|
-
if (!(options && options.lazy) && result)
|
|
182
|
-
result = result.toJSON();
|
|
183
|
-
position$1 = srcEnd;
|
|
184
|
-
} else
|
|
185
|
-
result = read();
|
|
176
|
+
let result = read();
|
|
186
177
|
if (bundledStrings$1) { // bundled strings to skip past
|
|
187
178
|
position$1 = bundledStrings$1.postBundlePosition;
|
|
188
179
|
bundledStrings$1 = null;
|
|
@@ -202,7 +193,7 @@
|
|
|
202
193
|
referenceMap = null;
|
|
203
194
|
} else if (position$1 > srcEnd) {
|
|
204
195
|
// over read
|
|
205
|
-
throw new Error('Unexpected end of MessagePack data')
|
|
196
|
+
throw new Error('Unexpected end of MessagePack data');
|
|
206
197
|
} else if (!sequentialMode) {
|
|
207
198
|
let jsonView;
|
|
208
199
|
try {
|
|
@@ -210,10 +201,10 @@
|
|
|
210
201
|
} catch(error) {
|
|
211
202
|
jsonView = '(JSON view not available ' + error + ')';
|
|
212
203
|
}
|
|
213
|
-
throw new Error('Data read, but end of buffer not reached ' + jsonView)
|
|
204
|
+
throw new Error('Data read, but end of buffer not reached ' + jsonView);
|
|
214
205
|
}
|
|
215
206
|
// else more to read, but we are reading sequentially, so don't clear source yet
|
|
216
|
-
return result
|
|
207
|
+
return result;
|
|
217
208
|
} catch(error) {
|
|
218
209
|
if (currentStructures && currentStructures.restoreStructures)
|
|
219
210
|
restoreStructures();
|
|
@@ -221,7 +212,7 @@
|
|
|
221
212
|
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
|
|
222
213
|
error.incomplete = true;
|
|
223
214
|
}
|
|
224
|
-
throw error
|
|
215
|
+
throw error;
|
|
225
216
|
}
|
|
226
217
|
}
|
|
227
218
|
|
|
@@ -237,7 +228,7 @@
|
|
|
237
228
|
if (token < 0xa0) {
|
|
238
229
|
if (token < 0x80) {
|
|
239
230
|
if (token < 0x40)
|
|
240
|
-
return token
|
|
231
|
+
return token;
|
|
241
232
|
else {
|
|
242
233
|
let structure = currentStructures[token & 0x3f] ||
|
|
243
234
|
currentUnpackr.getStructures && loadStructures()[token & 0x3f];
|
|
@@ -245,9 +236,9 @@
|
|
|
245
236
|
if (!structure.read) {
|
|
246
237
|
structure.read = createStructureReader(structure, token & 0x3f);
|
|
247
238
|
}
|
|
248
|
-
return structure.read()
|
|
239
|
+
return structure.read();
|
|
249
240
|
} else
|
|
250
|
-
return token
|
|
241
|
+
return token;
|
|
251
242
|
}
|
|
252
243
|
} else if (token < 0x90) {
|
|
253
244
|
// map
|
|
@@ -260,13 +251,13 @@
|
|
|
260
251
|
key = '__proto_';
|
|
261
252
|
object[key] = read();
|
|
262
253
|
}
|
|
263
|
-
return object
|
|
254
|
+
return object;
|
|
264
255
|
} else {
|
|
265
256
|
let map = new Map();
|
|
266
257
|
for (let i = 0; i < token; i++) {
|
|
267
258
|
map.set(read(), read());
|
|
268
259
|
}
|
|
269
|
-
return map
|
|
260
|
+
return map;
|
|
270
261
|
}
|
|
271
262
|
} else {
|
|
272
263
|
token -= 0x90;
|
|
@@ -275,91 +266,91 @@
|
|
|
275
266
|
array[i] = read();
|
|
276
267
|
}
|
|
277
268
|
if (currentUnpackr.freezeData)
|
|
278
|
-
return Object.freeze(array)
|
|
279
|
-
return array
|
|
269
|
+
return Object.freeze(array);
|
|
270
|
+
return array;
|
|
280
271
|
}
|
|
281
272
|
} else if (token < 0xc0) {
|
|
282
273
|
// fixstr
|
|
283
274
|
let length = token - 0xa0;
|
|
284
275
|
if (srcStringEnd >= position$1) {
|
|
285
|
-
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
|
|
276
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
|
|
286
277
|
}
|
|
287
278
|
if (srcStringEnd == 0 && srcEnd < 140) {
|
|
288
279
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
289
280
|
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
290
281
|
if (string != null)
|
|
291
|
-
return string
|
|
282
|
+
return string;
|
|
292
283
|
}
|
|
293
|
-
return readFixedString(length)
|
|
284
|
+
return readFixedString(length);
|
|
294
285
|
} else {
|
|
295
286
|
let value;
|
|
296
287
|
switch (token) {
|
|
297
|
-
case 0xc0: return null
|
|
288
|
+
case 0xc0: return null;
|
|
298
289
|
case 0xc1:
|
|
299
290
|
if (bundledStrings$1) {
|
|
300
291
|
value = read(); // followed by the length of the string in characters (not bytes!)
|
|
301
292
|
if (value > 0)
|
|
302
|
-
return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
|
|
293
|
+
return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
|
|
303
294
|
else
|
|
304
|
-
return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
|
|
295
|
+
return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
|
|
305
296
|
}
|
|
306
297
|
return C1; // "never-used", return special object to denote that
|
|
307
|
-
case 0xc2: return false
|
|
308
|
-
case 0xc3: return true
|
|
298
|
+
case 0xc2: return false;
|
|
299
|
+
case 0xc3: return true;
|
|
309
300
|
case 0xc4:
|
|
310
301
|
// bin 8
|
|
311
302
|
value = src[position$1++];
|
|
312
303
|
if (value === undefined)
|
|
313
|
-
throw new Error('Unexpected end of buffer')
|
|
314
|
-
return readBin(value)
|
|
304
|
+
throw new Error('Unexpected end of buffer');
|
|
305
|
+
return readBin(value);
|
|
315
306
|
case 0xc5:
|
|
316
307
|
// bin 16
|
|
317
308
|
value = dataView.getUint16(position$1);
|
|
318
309
|
position$1 += 2;
|
|
319
|
-
return readBin(value)
|
|
310
|
+
return readBin(value);
|
|
320
311
|
case 0xc6:
|
|
321
312
|
// bin 32
|
|
322
313
|
value = dataView.getUint32(position$1);
|
|
323
314
|
position$1 += 4;
|
|
324
|
-
return readBin(value)
|
|
315
|
+
return readBin(value);
|
|
325
316
|
case 0xc7:
|
|
326
317
|
// ext 8
|
|
327
|
-
return readExt(src[position$1++])
|
|
318
|
+
return readExt(src[position$1++]);
|
|
328
319
|
case 0xc8:
|
|
329
320
|
// ext 16
|
|
330
321
|
value = dataView.getUint16(position$1);
|
|
331
322
|
position$1 += 2;
|
|
332
|
-
return readExt(value)
|
|
323
|
+
return readExt(value);
|
|
333
324
|
case 0xc9:
|
|
334
325
|
// ext 32
|
|
335
326
|
value = dataView.getUint32(position$1);
|
|
336
327
|
position$1 += 4;
|
|
337
|
-
return readExt(value)
|
|
328
|
+
return readExt(value);
|
|
338
329
|
case 0xca:
|
|
339
330
|
value = dataView.getFloat32(position$1);
|
|
340
331
|
if (currentUnpackr.useFloat32 > 2) {
|
|
341
332
|
// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
342
333
|
let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
|
|
343
334
|
position$1 += 4;
|
|
344
|
-
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
335
|
+
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
345
336
|
}
|
|
346
337
|
position$1 += 4;
|
|
347
|
-
return value
|
|
338
|
+
return value;
|
|
348
339
|
case 0xcb:
|
|
349
340
|
value = dataView.getFloat64(position$1);
|
|
350
341
|
position$1 += 8;
|
|
351
|
-
return value
|
|
342
|
+
return value;
|
|
352
343
|
// uint handlers
|
|
353
344
|
case 0xcc:
|
|
354
|
-
return src[position$1++]
|
|
345
|
+
return src[position$1++];
|
|
355
346
|
case 0xcd:
|
|
356
347
|
value = dataView.getUint16(position$1);
|
|
357
348
|
position$1 += 2;
|
|
358
|
-
return value
|
|
349
|
+
return value;
|
|
359
350
|
case 0xce:
|
|
360
351
|
value = dataView.getUint32(position$1);
|
|
361
352
|
position$1 += 4;
|
|
362
|
-
return value
|
|
353
|
+
return value;
|
|
363
354
|
case 0xcf:
|
|
364
355
|
if (currentUnpackr.int64AsType === 'number') {
|
|
365
356
|
value = dataView.getUint32(position$1) * 0x100000000;
|
|
@@ -372,19 +363,19 @@
|
|
|
372
363
|
} else
|
|
373
364
|
value = dataView.getBigUint64(position$1);
|
|
374
365
|
position$1 += 8;
|
|
375
|
-
return value
|
|
366
|
+
return value;
|
|
376
367
|
|
|
377
368
|
// int handlers
|
|
378
369
|
case 0xd0:
|
|
379
|
-
return dataView.getInt8(position$1++)
|
|
370
|
+
return dataView.getInt8(position$1++);
|
|
380
371
|
case 0xd1:
|
|
381
372
|
value = dataView.getInt16(position$1);
|
|
382
373
|
position$1 += 2;
|
|
383
|
-
return value
|
|
374
|
+
return value;
|
|
384
375
|
case 0xd2:
|
|
385
376
|
value = dataView.getInt32(position$1);
|
|
386
377
|
position$1 += 4;
|
|
387
|
-
return value
|
|
378
|
+
return value;
|
|
388
379
|
case 0xd3:
|
|
389
380
|
if (currentUnpackr.int64AsType === 'number') {
|
|
390
381
|
value = dataView.getInt32(position$1) * 0x100000000;
|
|
@@ -397,96 +388,96 @@
|
|
|
397
388
|
} else
|
|
398
389
|
value = dataView.getBigInt64(position$1);
|
|
399
390
|
position$1 += 8;
|
|
400
|
-
return value
|
|
391
|
+
return value;
|
|
401
392
|
|
|
402
393
|
case 0xd4:
|
|
403
394
|
// fixext 1
|
|
404
395
|
value = src[position$1++];
|
|
405
396
|
if (value == 0x72) {
|
|
406
|
-
return recordDefinition(src[position$1++] & 0x3f)
|
|
397
|
+
return recordDefinition(src[position$1++] & 0x3f);
|
|
407
398
|
} else {
|
|
408
399
|
let extension = currentExtensions[value];
|
|
409
400
|
if (extension) {
|
|
410
401
|
if (extension.read) {
|
|
411
402
|
position$1++; // skip filler byte
|
|
412
|
-
return extension.read(read())
|
|
403
|
+
return extension.read(read());
|
|
413
404
|
} else if (extension.noBuffer) {
|
|
414
405
|
position$1++; // skip filler byte
|
|
415
|
-
return extension()
|
|
406
|
+
return extension();
|
|
416
407
|
} else
|
|
417
|
-
return extension(src.subarray(position$1, ++position$1))
|
|
408
|
+
return extension(src.subarray(position$1, ++position$1));
|
|
418
409
|
} else
|
|
419
|
-
throw new Error('Unknown extension ' + value)
|
|
410
|
+
throw new Error('Unknown extension ' + value);
|
|
420
411
|
}
|
|
421
412
|
case 0xd5:
|
|
422
413
|
// fixext 2
|
|
423
414
|
value = src[position$1];
|
|
424
415
|
if (value == 0x72) {
|
|
425
416
|
position$1++;
|
|
426
|
-
return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
|
|
417
|
+
return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
|
|
427
418
|
} else
|
|
428
|
-
return readExt(2)
|
|
419
|
+
return readExt(2);
|
|
429
420
|
case 0xd6:
|
|
430
421
|
// fixext 4
|
|
431
|
-
return readExt(4)
|
|
422
|
+
return readExt(4);
|
|
432
423
|
case 0xd7:
|
|
433
424
|
// fixext 8
|
|
434
|
-
return readExt(8)
|
|
425
|
+
return readExt(8);
|
|
435
426
|
case 0xd8:
|
|
436
427
|
// fixext 16
|
|
437
|
-
return readExt(16)
|
|
428
|
+
return readExt(16);
|
|
438
429
|
case 0xd9:
|
|
439
430
|
// str 8
|
|
440
431
|
value = src[position$1++];
|
|
441
432
|
if (srcStringEnd >= position$1) {
|
|
442
|
-
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
433
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
|
|
443
434
|
}
|
|
444
|
-
return readString8(value)
|
|
435
|
+
return readString8(value);
|
|
445
436
|
case 0xda:
|
|
446
437
|
// str 16
|
|
447
438
|
value = dataView.getUint16(position$1);
|
|
448
439
|
position$1 += 2;
|
|
449
440
|
if (srcStringEnd >= position$1) {
|
|
450
|
-
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
441
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
|
|
451
442
|
}
|
|
452
|
-
return readString16(value)
|
|
443
|
+
return readString16(value);
|
|
453
444
|
case 0xdb:
|
|
454
445
|
// str 32
|
|
455
446
|
value = dataView.getUint32(position$1);
|
|
456
447
|
position$1 += 4;
|
|
457
448
|
if (srcStringEnd >= position$1) {
|
|
458
|
-
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
|
|
449
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
|
|
459
450
|
}
|
|
460
|
-
return readString32(value)
|
|
451
|
+
return readString32(value);
|
|
461
452
|
case 0xdc:
|
|
462
453
|
// array 16
|
|
463
454
|
value = dataView.getUint16(position$1);
|
|
464
455
|
position$1 += 2;
|
|
465
|
-
return readArray(value)
|
|
456
|
+
return readArray(value);
|
|
466
457
|
case 0xdd:
|
|
467
458
|
// array 32
|
|
468
459
|
value = dataView.getUint32(position$1);
|
|
469
460
|
position$1 += 4;
|
|
470
|
-
return readArray(value)
|
|
461
|
+
return readArray(value);
|
|
471
462
|
case 0xde:
|
|
472
463
|
// map 16
|
|
473
464
|
value = dataView.getUint16(position$1);
|
|
474
465
|
position$1 += 2;
|
|
475
|
-
return readMap(value)
|
|
466
|
+
return readMap(value);
|
|
476
467
|
case 0xdf:
|
|
477
468
|
// map 32
|
|
478
469
|
value = dataView.getUint32(position$1);
|
|
479
470
|
position$1 += 4;
|
|
480
|
-
return readMap(value)
|
|
471
|
+
return readMap(value);
|
|
481
472
|
default: // negative int
|
|
482
473
|
if (token >= 0xe0)
|
|
483
|
-
return token - 0x100
|
|
474
|
+
return token - 0x100;
|
|
484
475
|
if (token === undefined) {
|
|
485
476
|
let error = new Error('Unexpected end of MessagePack data');
|
|
486
477
|
error.incomplete = true;
|
|
487
|
-
throw error
|
|
478
|
+
throw error;
|
|
488
479
|
}
|
|
489
|
-
throw new Error('Unknown MessagePack token ' + token)
|
|
480
|
+
throw new Error('Unknown MessagePack token ' + token);
|
|
490
481
|
|
|
491
482
|
}
|
|
492
483
|
}
|
|
@@ -507,7 +498,7 @@
|
|
|
507
498
|
}
|
|
508
499
|
if (structure.highByte === 0)
|
|
509
500
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
510
|
-
return optimizedReadObject() // second byte is already read, if there is one so immediately read object
|
|
501
|
+
return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
|
|
511
502
|
}
|
|
512
503
|
let object = {};
|
|
513
504
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
@@ -518,38 +509,38 @@
|
|
|
518
509
|
}
|
|
519
510
|
if (currentUnpackr.freezeData)
|
|
520
511
|
return Object.freeze(object);
|
|
521
|
-
return object
|
|
512
|
+
return object;
|
|
522
513
|
}
|
|
523
514
|
readObject.count = 0;
|
|
524
515
|
if (structure.highByte === 0) {
|
|
525
|
-
return createSecondByteReader(firstId, readObject)
|
|
516
|
+
return createSecondByteReader(firstId, readObject);
|
|
526
517
|
}
|
|
527
|
-
return readObject
|
|
518
|
+
return readObject;
|
|
528
519
|
}
|
|
529
520
|
|
|
530
521
|
const createSecondByteReader = (firstId, read0) => {
|
|
531
522
|
return function() {
|
|
532
523
|
let highByte = src[position$1++];
|
|
533
524
|
if (highByte === 0)
|
|
534
|
-
return read0()
|
|
525
|
+
return read0();
|
|
535
526
|
let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
|
|
536
527
|
let structure = currentStructures[id] || loadStructures()[id];
|
|
537
528
|
if (!structure) {
|
|
538
|
-
throw new Error('Record id is not defined for ' + id)
|
|
529
|
+
throw new Error('Record id is not defined for ' + id);
|
|
539
530
|
}
|
|
540
531
|
if (!structure.read)
|
|
541
532
|
structure.read = createStructureReader(structure, firstId);
|
|
542
|
-
return structure.read()
|
|
543
|
-
}
|
|
533
|
+
return structure.read();
|
|
534
|
+
};
|
|
544
535
|
};
|
|
545
536
|
|
|
546
537
|
function loadStructures() {
|
|
547
538
|
let loadedStructures = saveState(() => {
|
|
548
539
|
// save the state in case getStructures modifies our buffer
|
|
549
540
|
src = null;
|
|
550
|
-
return currentUnpackr.getStructures()
|
|
541
|
+
return currentUnpackr.getStructures();
|
|
551
542
|
});
|
|
552
|
-
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
|
|
543
|
+
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
|
|
553
544
|
}
|
|
554
545
|
|
|
555
546
|
var readFixedString = readStringJS;
|
|
@@ -561,10 +552,10 @@
|
|
|
561
552
|
let result;
|
|
562
553
|
if (length < 16) {
|
|
563
554
|
if (result = shortStringInJS(length))
|
|
564
|
-
return result
|
|
555
|
+
return result;
|
|
565
556
|
}
|
|
566
557
|
if (length > 64 && decoder)
|
|
567
|
-
return decoder.decode(src.subarray(position$1, position$1 += length))
|
|
558
|
+
return decoder.decode(src.subarray(position$1, position$1 += length));
|
|
568
559
|
const end = position$1 + length;
|
|
569
560
|
const units = [];
|
|
570
561
|
result = '';
|
|
@@ -627,7 +618,7 @@
|
|
|
627
618
|
result += fromCharCode.apply(String, units);
|
|
628
619
|
}
|
|
629
620
|
|
|
630
|
-
return result
|
|
621
|
+
return result;
|
|
631
622
|
}
|
|
632
623
|
|
|
633
624
|
function readArray(length) {
|
|
@@ -636,8 +627,8 @@
|
|
|
636
627
|
array[i] = read();
|
|
637
628
|
}
|
|
638
629
|
if (currentUnpackr.freezeData)
|
|
639
|
-
return Object.freeze(array)
|
|
640
|
-
return array
|
|
630
|
+
return Object.freeze(array);
|
|
631
|
+
return array;
|
|
641
632
|
}
|
|
642
633
|
|
|
643
634
|
function readMap(length) {
|
|
@@ -649,13 +640,13 @@
|
|
|
649
640
|
key = '__proto_';
|
|
650
641
|
object[key] = read();
|
|
651
642
|
}
|
|
652
|
-
return object
|
|
643
|
+
return object;
|
|
653
644
|
} else {
|
|
654
645
|
let map = new Map();
|
|
655
646
|
for (let i = 0; i < length; i++) {
|
|
656
647
|
map.set(read(), read());
|
|
657
648
|
}
|
|
658
|
-
return map
|
|
649
|
+
return map;
|
|
659
650
|
}
|
|
660
651
|
}
|
|
661
652
|
|
|
@@ -667,40 +658,40 @@
|
|
|
667
658
|
const byte = src[position$1++];
|
|
668
659
|
if ((byte & 0x80) > 0) {
|
|
669
660
|
position$1 = start;
|
|
670
|
-
return
|
|
661
|
+
return;
|
|
671
662
|
}
|
|
672
663
|
bytes[i] = byte;
|
|
673
664
|
}
|
|
674
|
-
return fromCharCode.apply(String, bytes)
|
|
665
|
+
return fromCharCode.apply(String, bytes);
|
|
675
666
|
}
|
|
676
667
|
function shortStringInJS(length) {
|
|
677
668
|
if (length < 4) {
|
|
678
669
|
if (length < 2) {
|
|
679
670
|
if (length === 0)
|
|
680
|
-
return ''
|
|
671
|
+
return '';
|
|
681
672
|
else {
|
|
682
673
|
let a = src[position$1++];
|
|
683
674
|
if ((a & 0x80) > 1) {
|
|
684
675
|
position$1 -= 1;
|
|
685
|
-
return
|
|
676
|
+
return;
|
|
686
677
|
}
|
|
687
|
-
return fromCharCode(a)
|
|
678
|
+
return fromCharCode(a);
|
|
688
679
|
}
|
|
689
680
|
} else {
|
|
690
681
|
let a = src[position$1++];
|
|
691
682
|
let b = src[position$1++];
|
|
692
683
|
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
|
|
693
684
|
position$1 -= 2;
|
|
694
|
-
return
|
|
685
|
+
return;
|
|
695
686
|
}
|
|
696
687
|
if (length < 3)
|
|
697
|
-
return fromCharCode(a, b)
|
|
688
|
+
return fromCharCode(a, b);
|
|
698
689
|
let c = src[position$1++];
|
|
699
690
|
if ((c & 0x80) > 0) {
|
|
700
691
|
position$1 -= 3;
|
|
701
|
-
return
|
|
692
|
+
return;
|
|
702
693
|
}
|
|
703
|
-
return fromCharCode(a, b, c)
|
|
694
|
+
return fromCharCode(a, b, c);
|
|
704
695
|
}
|
|
705
696
|
} else {
|
|
706
697
|
let a = src[position$1++];
|
|
@@ -709,34 +700,34 @@
|
|
|
709
700
|
let d = src[position$1++];
|
|
710
701
|
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
|
|
711
702
|
position$1 -= 4;
|
|
712
|
-
return
|
|
703
|
+
return;
|
|
713
704
|
}
|
|
714
705
|
if (length < 6) {
|
|
715
706
|
if (length === 4)
|
|
716
|
-
return fromCharCode(a, b, c, d)
|
|
707
|
+
return fromCharCode(a, b, c, d);
|
|
717
708
|
else {
|
|
718
709
|
let e = src[position$1++];
|
|
719
710
|
if ((e & 0x80) > 0) {
|
|
720
711
|
position$1 -= 5;
|
|
721
|
-
return
|
|
712
|
+
return;
|
|
722
713
|
}
|
|
723
|
-
return fromCharCode(a, b, c, d, e)
|
|
714
|
+
return fromCharCode(a, b, c, d, e);
|
|
724
715
|
}
|
|
725
716
|
} else if (length < 8) {
|
|
726
717
|
let e = src[position$1++];
|
|
727
718
|
let f = src[position$1++];
|
|
728
719
|
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
|
|
729
720
|
position$1 -= 6;
|
|
730
|
-
return
|
|
721
|
+
return;
|
|
731
722
|
}
|
|
732
723
|
if (length < 7)
|
|
733
|
-
return fromCharCode(a, b, c, d, e, f)
|
|
724
|
+
return fromCharCode(a, b, c, d, e, f);
|
|
734
725
|
let g = src[position$1++];
|
|
735
726
|
if ((g & 0x80) > 0) {
|
|
736
727
|
position$1 -= 7;
|
|
737
|
-
return
|
|
728
|
+
return;
|
|
738
729
|
}
|
|
739
|
-
return fromCharCode(a, b, c, d, e, f, g)
|
|
730
|
+
return fromCharCode(a, b, c, d, e, f, g);
|
|
740
731
|
} else {
|
|
741
732
|
let e = src[position$1++];
|
|
742
733
|
let f = src[position$1++];
|
|
@@ -744,34 +735,34 @@
|
|
|
744
735
|
let h = src[position$1++];
|
|
745
736
|
if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
|
|
746
737
|
position$1 -= 8;
|
|
747
|
-
return
|
|
738
|
+
return;
|
|
748
739
|
}
|
|
749
740
|
if (length < 10) {
|
|
750
741
|
if (length === 8)
|
|
751
|
-
return fromCharCode(a, b, c, d, e, f, g, h)
|
|
742
|
+
return fromCharCode(a, b, c, d, e, f, g, h);
|
|
752
743
|
else {
|
|
753
744
|
let i = src[position$1++];
|
|
754
745
|
if ((i & 0x80) > 0) {
|
|
755
746
|
position$1 -= 9;
|
|
756
|
-
return
|
|
747
|
+
return;
|
|
757
748
|
}
|
|
758
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i)
|
|
749
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i);
|
|
759
750
|
}
|
|
760
751
|
} else if (length < 12) {
|
|
761
752
|
let i = src[position$1++];
|
|
762
753
|
let j = src[position$1++];
|
|
763
754
|
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
|
|
764
755
|
position$1 -= 10;
|
|
765
|
-
return
|
|
756
|
+
return;
|
|
766
757
|
}
|
|
767
758
|
if (length < 11)
|
|
768
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j)
|
|
759
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j);
|
|
769
760
|
let k = src[position$1++];
|
|
770
761
|
if ((k & 0x80) > 0) {
|
|
771
762
|
position$1 -= 11;
|
|
772
|
-
return
|
|
763
|
+
return;
|
|
773
764
|
}
|
|
774
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
|
|
765
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
|
|
775
766
|
} else {
|
|
776
767
|
let i = src[position$1++];
|
|
777
768
|
let j = src[position$1++];
|
|
@@ -779,34 +770,34 @@
|
|
|
779
770
|
let l = src[position$1++];
|
|
780
771
|
if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
|
|
781
772
|
position$1 -= 12;
|
|
782
|
-
return
|
|
773
|
+
return;
|
|
783
774
|
}
|
|
784
775
|
if (length < 14) {
|
|
785
776
|
if (length === 12)
|
|
786
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
|
|
777
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
|
|
787
778
|
else {
|
|
788
779
|
let m = src[position$1++];
|
|
789
780
|
if ((m & 0x80) > 0) {
|
|
790
781
|
position$1 -= 13;
|
|
791
|
-
return
|
|
782
|
+
return;
|
|
792
783
|
}
|
|
793
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
|
|
784
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
|
|
794
785
|
}
|
|
795
786
|
} else {
|
|
796
787
|
let m = src[position$1++];
|
|
797
788
|
let n = src[position$1++];
|
|
798
789
|
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
|
|
799
790
|
position$1 -= 14;
|
|
800
|
-
return
|
|
791
|
+
return;
|
|
801
792
|
}
|
|
802
793
|
if (length < 15)
|
|
803
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
|
|
794
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
|
|
804
795
|
let o = src[position$1++];
|
|
805
796
|
if ((o & 0x80) > 0) {
|
|
806
797
|
position$1 -= 15;
|
|
807
|
-
return
|
|
798
|
+
return;
|
|
808
799
|
}
|
|
809
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
|
|
800
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
|
|
810
801
|
}
|
|
811
802
|
}
|
|
812
803
|
}
|
|
@@ -824,22 +815,22 @@
|
|
|
824
815
|
case 0xd9:
|
|
825
816
|
// str 8
|
|
826
817
|
length = src[position$1++];
|
|
827
|
-
break
|
|
818
|
+
break;
|
|
828
819
|
case 0xda:
|
|
829
820
|
// str 16
|
|
830
821
|
length = dataView.getUint16(position$1);
|
|
831
822
|
position$1 += 2;
|
|
832
|
-
break
|
|
823
|
+
break;
|
|
833
824
|
case 0xdb:
|
|
834
825
|
// str 32
|
|
835
826
|
length = dataView.getUint32(position$1);
|
|
836
827
|
position$1 += 4;
|
|
837
|
-
break
|
|
828
|
+
break;
|
|
838
829
|
default:
|
|
839
|
-
throw new Error('Expected string')
|
|
830
|
+
throw new Error('Expected string');
|
|
840
831
|
}
|
|
841
832
|
}
|
|
842
|
-
return readStringJS(length)
|
|
833
|
+
return readStringJS(length);
|
|
843
834
|
}
|
|
844
835
|
|
|
845
836
|
|
|
@@ -847,7 +838,7 @@
|
|
|
847
838
|
return currentUnpackr.copyBuffers ?
|
|
848
839
|
// specifically use the copying slice (not the node one)
|
|
849
840
|
Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
|
|
850
|
-
src.subarray(position$1, position$1 += length)
|
|
841
|
+
src.subarray(position$1, position$1 += length);
|
|
851
842
|
}
|
|
852
843
|
function readExt(length) {
|
|
853
844
|
let type = src[position$1++];
|
|
@@ -860,10 +851,10 @@
|
|
|
860
851
|
} finally {
|
|
861
852
|
position$1 = end;
|
|
862
853
|
}
|
|
863
|
-
})
|
|
854
|
+
});
|
|
864
855
|
}
|
|
865
856
|
else
|
|
866
|
-
throw new Error('Unknown extension type ' + type)
|
|
857
|
+
throw new Error('Unknown extension type ' + type);
|
|
867
858
|
}
|
|
868
859
|
|
|
869
860
|
var keyCache = new Array(4096);
|
|
@@ -873,12 +864,12 @@
|
|
|
873
864
|
// fixstr, potentially use key cache
|
|
874
865
|
length = length - 0xa0;
|
|
875
866
|
if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
|
|
876
|
-
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
|
|
867
|
+
return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
|
|
877
868
|
else if (!(srcStringEnd == 0 && srcEnd < 180))
|
|
878
|
-
return readFixedString(length)
|
|
869
|
+
return readFixedString(length);
|
|
879
870
|
} else { // not cacheable, go back and do a standard read
|
|
880
871
|
position$1--;
|
|
881
|
-
return asSafeString(read())
|
|
872
|
+
return asSafeString(read());
|
|
882
873
|
}
|
|
883
874
|
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
|
|
884
875
|
let entry = keyCache[key];
|
|
@@ -891,7 +882,7 @@
|
|
|
891
882
|
chunk = dataView.getUint32(checkPosition);
|
|
892
883
|
if (chunk != entry[i++]) {
|
|
893
884
|
checkPosition = 0x70000000;
|
|
894
|
-
break
|
|
885
|
+
break;
|
|
895
886
|
}
|
|
896
887
|
checkPosition += 4;
|
|
897
888
|
}
|
|
@@ -900,12 +891,12 @@
|
|
|
900
891
|
chunk = src[checkPosition++];
|
|
901
892
|
if (chunk != entry[i++]) {
|
|
902
893
|
checkPosition = 0x70000000;
|
|
903
|
-
break
|
|
894
|
+
break;
|
|
904
895
|
}
|
|
905
896
|
}
|
|
906
897
|
if (checkPosition === end) {
|
|
907
898
|
position$1 = checkPosition;
|
|
908
|
-
return entry.string
|
|
899
|
+
return entry.string;
|
|
909
900
|
}
|
|
910
901
|
end -= 3;
|
|
911
902
|
checkPosition = position$1;
|
|
@@ -926,8 +917,8 @@
|
|
|
926
917
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
927
918
|
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
928
919
|
if (string != null)
|
|
929
|
-
return entry.string = string
|
|
930
|
-
return entry.string = readFixedString(length)
|
|
920
|
+
return entry.string = string;
|
|
921
|
+
return entry.string = readFixedString(length);
|
|
931
922
|
}
|
|
932
923
|
|
|
933
924
|
function asSafeString(property) {
|
|
@@ -958,7 +949,7 @@
|
|
|
958
949
|
}
|
|
959
950
|
currentStructures[id] = structure;
|
|
960
951
|
structure.read = createStructureReader(structure, firstByte);
|
|
961
|
-
return structure.read()
|
|
952
|
+
return structure.read();
|
|
962
953
|
};
|
|
963
954
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
964
955
|
currentExtensions[0].noBuffer = true;
|
|
@@ -980,17 +971,17 @@
|
|
|
980
971
|
out <<= BigInt(64);
|
|
981
972
|
out |= view.getBigUint64(i);
|
|
982
973
|
}
|
|
983
|
-
return out
|
|
974
|
+
return out;
|
|
984
975
|
}
|
|
985
976
|
// if (length === 8) return view.getBigUint64(start)
|
|
986
977
|
let middle = start + (length >> 4 << 3);
|
|
987
978
|
let left = decode(start, middle);
|
|
988
979
|
let right = decode(middle, end);
|
|
989
|
-
return (left << BigInt((end - middle) * 8)) | right
|
|
980
|
+
return (left << BigInt((end - middle) * 8)) | right;
|
|
990
981
|
};
|
|
991
982
|
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
|
|
992
983
|
}
|
|
993
|
-
return head
|
|
984
|
+
return head;
|
|
994
985
|
};
|
|
995
986
|
|
|
996
987
|
let errors = {
|
|
@@ -1001,14 +992,14 @@
|
|
|
1001
992
|
if (!errors[data[0]]) {
|
|
1002
993
|
let error = Error(data[1], { cause: data[2] });
|
|
1003
994
|
error.name = data[0];
|
|
1004
|
-
return error
|
|
995
|
+
return error;
|
|
1005
996
|
}
|
|
1006
|
-
return errors[data[0]](data[1], { cause: data[2] })
|
|
997
|
+
return errors[data[0]](data[1], { cause: data[2] });
|
|
1007
998
|
};
|
|
1008
999
|
|
|
1009
1000
|
currentExtensions[0x69] = (data) => {
|
|
1010
1001
|
// id extension (for structured clones)
|
|
1011
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1002
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1012
1003
|
let id = dataView.getUint32(position$1 - 4);
|
|
1013
1004
|
if (!referenceMap)
|
|
1014
1005
|
referenceMap = new Map();
|
|
@@ -1029,7 +1020,7 @@
|
|
|
1029
1020
|
let targetProperties = read(); // read the next value as the target object to id
|
|
1030
1021
|
if (!refEntry.used) {
|
|
1031
1022
|
// no cycle, can just use the returned read object
|
|
1032
|
-
return refEntry.target = targetProperties // replace the placeholder with the real one
|
|
1023
|
+
return refEntry.target = targetProperties; // replace the placeholder with the real one
|
|
1033
1024
|
} else {
|
|
1034
1025
|
// there is a cycle, so we have to assign properties to original target
|
|
1035
1026
|
Object.assign(target, targetProperties);
|
|
@@ -1040,16 +1031,16 @@
|
|
|
1040
1031
|
for (let [k, v] of targetProperties.entries()) target.set(k, v);
|
|
1041
1032
|
if (target instanceof Set)
|
|
1042
1033
|
for (let i of Array.from(targetProperties)) target.add(i);
|
|
1043
|
-
return target
|
|
1034
|
+
return target;
|
|
1044
1035
|
};
|
|
1045
1036
|
|
|
1046
1037
|
currentExtensions[0x70] = (data) => {
|
|
1047
1038
|
// pointer extension (for structured clones)
|
|
1048
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1039
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1049
1040
|
let id = dataView.getUint32(position$1 - 4);
|
|
1050
1041
|
let refEntry = referenceMap.get(id);
|
|
1051
1042
|
refEntry.used = true;
|
|
1052
|
-
return refEntry.target
|
|
1043
|
+
return refEntry.target;
|
|
1053
1044
|
};
|
|
1054
1045
|
|
|
1055
1046
|
currentExtensions[0x73] = () => new Set(read());
|
|
@@ -1064,15 +1055,15 @@
|
|
|
1064
1055
|
|
|
1065
1056
|
let typedArrayName = typedArrays[typeCode];
|
|
1066
1057
|
if (!typedArrayName) {
|
|
1067
|
-
if (typeCode === 16) return buffer
|
|
1068
|
-
if (typeCode === 17) return new DataView(buffer)
|
|
1069
|
-
throw new Error('Could not find typed array for code ' + typeCode)
|
|
1058
|
+
if (typeCode === 16) return buffer;
|
|
1059
|
+
if (typeCode === 17) return new DataView(buffer);
|
|
1060
|
+
throw new Error('Could not find typed array for code ' + typeCode);
|
|
1070
1061
|
}
|
|
1071
|
-
return new glbl[typedArrayName](buffer)
|
|
1062
|
+
return new glbl[typedArrayName](buffer);
|
|
1072
1063
|
};
|
|
1073
1064
|
currentExtensions[0x78] = () => {
|
|
1074
1065
|
let data = read();
|
|
1075
|
-
return new RegExp(data[0], data[1])
|
|
1066
|
+
return new RegExp(data[0], data[1]);
|
|
1076
1067
|
};
|
|
1077
1068
|
const TEMP_BUNDLE = [];
|
|
1078
1069
|
currentExtensions[0x62] = (data) => {
|
|
@@ -1085,23 +1076,23 @@
|
|
|
1085
1076
|
bundledStrings$1.position1 = 0;
|
|
1086
1077
|
bundledStrings$1.postBundlePosition = position$1;
|
|
1087
1078
|
position$1 = dataPosition;
|
|
1088
|
-
return read()
|
|
1079
|
+
return read();
|
|
1089
1080
|
};
|
|
1090
1081
|
|
|
1091
1082
|
currentExtensions[0xff] = (data) => {
|
|
1092
1083
|
// 32-bit date extension
|
|
1093
1084
|
if (data.length == 4)
|
|
1094
|
-
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
|
|
1085
|
+
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
|
|
1095
1086
|
else if (data.length == 8)
|
|
1096
1087
|
return new Date(
|
|
1097
1088
|
((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
|
|
1098
|
-
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
|
|
1089
|
+
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
|
|
1099
1090
|
else if (data.length == 12)
|
|
1100
1091
|
return new Date(
|
|
1101
1092
|
((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
|
|
1102
|
-
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
|
|
1093
|
+
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
|
|
1103
1094
|
else
|
|
1104
|
-
return new Date('invalid')
|
|
1095
|
+
return new Date('invalid');
|
|
1105
1096
|
};
|
|
1106
1097
|
// registration of bulk record definition?
|
|
1107
1098
|
// currentExtensions[0x52] = () =>
|
|
@@ -1135,7 +1126,7 @@
|
|
|
1135
1126
|
currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
|
|
1136
1127
|
currentUnpackr = savedPackr;
|
|
1137
1128
|
dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
1138
|
-
return value
|
|
1129
|
+
return value;
|
|
1139
1130
|
}
|
|
1140
1131
|
function clearSource() {
|
|
1141
1132
|
src = null;
|
|
@@ -1170,7 +1161,7 @@
|
|
|
1170
1161
|
function roundFloat32(float32Number) {
|
|
1171
1162
|
f32Array[0] = float32Number;
|
|
1172
1163
|
let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
|
|
1173
|
-
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
1164
|
+
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
1174
1165
|
}
|
|
1175
1166
|
|
|
1176
1167
|
let textEncoder;
|
|
@@ -1180,7 +1171,7 @@
|
|
|
1180
1171
|
let extensions, extensionClasses;
|
|
1181
1172
|
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
|
1182
1173
|
const ByteArrayAllocate = hasNodeBuffer ?
|
|
1183
|
-
function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
|
|
1174
|
+
function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
|
|
1184
1175
|
const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
|
|
1185
1176
|
const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
|
|
1186
1177
|
let target, keysTarget;
|
|
@@ -1188,7 +1179,6 @@
|
|
|
1188
1179
|
let position = 0;
|
|
1189
1180
|
let safeEnd;
|
|
1190
1181
|
let bundledStrings = null;
|
|
1191
|
-
let writeStructSlots;
|
|
1192
1182
|
const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
|
|
1193
1183
|
const hasNonLatin = /[\u0080-\uFFFF]/;
|
|
1194
1184
|
const RECORD_SYMBOL = Symbol('record-id');
|
|
@@ -1201,10 +1191,10 @@
|
|
|
1201
1191
|
let structures;
|
|
1202
1192
|
let referenceMap;
|
|
1203
1193
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1204
|
-
return target.utf8Write(string, position, target.byteLength - position)
|
|
1194
|
+
return target.utf8Write(string, position, target.byteLength - position);
|
|
1205
1195
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1206
1196
|
function(string, position) {
|
|
1207
|
-
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
1197
|
+
return textEncoder.encodeInto(string, target.subarray(position)).written;
|
|
1208
1198
|
} : false;
|
|
1209
1199
|
|
|
1210
1200
|
let packr = this;
|
|
@@ -1216,7 +1206,7 @@
|
|
|
1216
1206
|
if (maxSharedStructures == null)
|
|
1217
1207
|
maxSharedStructures = hasSharedStructures ? 32 : 0;
|
|
1218
1208
|
if (maxSharedStructures > 8160)
|
|
1219
|
-
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1209
|
+
throw new Error('Maximum maxSharedStructure is 8160');
|
|
1220
1210
|
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1221
1211
|
this.moreTypes = true;
|
|
1222
1212
|
}
|
|
@@ -1230,7 +1220,7 @@
|
|
|
1230
1220
|
let sharedLimitId = maxSharedStructures + 0x40;
|
|
1231
1221
|
let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
|
|
1232
1222
|
if (maxStructureId > 8256) {
|
|
1233
|
-
throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
|
|
1223
|
+
throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
|
|
1234
1224
|
}
|
|
1235
1225
|
let recordIdsToRemove = [];
|
|
1236
1226
|
let transitionsCount = 0;
|
|
@@ -1266,7 +1256,7 @@
|
|
|
1266
1256
|
let sharedLength = structures.sharedLength || 0;
|
|
1267
1257
|
if (sharedLength > maxSharedStructures) {
|
|
1268
1258
|
//if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
|
|
1269
|
-
throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
|
|
1259
|
+
throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
|
|
1270
1260
|
}
|
|
1271
1261
|
if (!structures.transitions) {
|
|
1272
1262
|
// rebuild our structure transitions
|
|
@@ -1274,7 +1264,7 @@
|
|
|
1274
1264
|
for (let i = 0; i < sharedLength; i++) {
|
|
1275
1265
|
let keys = structures[i];
|
|
1276
1266
|
if (!keys)
|
|
1277
|
-
continue
|
|
1267
|
+
continue;
|
|
1278
1268
|
let nextTransition, transition = structures.transitions;
|
|
1279
1269
|
for (let j = 0, l = keys.length; j < l; j++) {
|
|
1280
1270
|
let key = keys[j];
|
|
@@ -1296,14 +1286,7 @@
|
|
|
1296
1286
|
hasSharedUpdate = false;
|
|
1297
1287
|
let encodingError;
|
|
1298
1288
|
try {
|
|
1299
|
-
|
|
1300
|
-
if (value.constructor === Object) writeStruct(value); // simple object
|
|
1301
|
-
else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
|
|
1302
|
-
// allow user classes, if they don't need special handling (but do use toJSON if available)
|
|
1303
|
-
writeStruct(value.toJSON ? value.toJSON() : value);
|
|
1304
|
-
} else pack(value);
|
|
1305
|
-
} else
|
|
1306
|
-
pack(value);
|
|
1289
|
+
pack(value);
|
|
1307
1290
|
let lastBundle = bundledStrings;
|
|
1308
1291
|
if (bundledStrings)
|
|
1309
1292
|
writeBundles(start, pack, 0);
|
|
@@ -1340,15 +1323,15 @@
|
|
|
1340
1323
|
packr.offset = position;
|
|
1341
1324
|
let serialized = insertIds(target.subarray(start, position), idsToInsert);
|
|
1342
1325
|
referenceMap = null;
|
|
1343
|
-
return serialized
|
|
1326
|
+
return serialized;
|
|
1344
1327
|
}
|
|
1345
1328
|
packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1346
1329
|
if (encodeOptions & REUSE_BUFFER_MODE) {
|
|
1347
1330
|
target.start = start;
|
|
1348
1331
|
target.end = position;
|
|
1349
|
-
return target
|
|
1332
|
+
return target;
|
|
1350
1333
|
}
|
|
1351
|
-
return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
|
|
1334
|
+
return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
|
|
1352
1335
|
} catch(error) {
|
|
1353
1336
|
encodingError = error;
|
|
1354
1337
|
throw error;
|
|
@@ -1363,12 +1346,12 @@
|
|
|
1363
1346
|
if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
|
|
1364
1347
|
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
|
|
1365
1348
|
// get updated structures and try again if the update failed
|
|
1366
|
-
return packr.pack(value, encodeOptions)
|
|
1349
|
+
return packr.pack(value, encodeOptions);
|
|
1367
1350
|
}
|
|
1368
1351
|
packr.lastNamedStructuresLength = sharedLength;
|
|
1369
1352
|
// don't keep large buffers around
|
|
1370
1353
|
if (target.length > 0x40000000) target = null;
|
|
1371
|
-
return returnBuffer
|
|
1354
|
+
return returnBuffer;
|
|
1372
1355
|
}
|
|
1373
1356
|
}
|
|
1374
1357
|
}
|
|
@@ -1454,7 +1437,7 @@
|
|
|
1454
1437
|
bundledStrings[twoByte ? 0 : 1] += value;
|
|
1455
1438
|
target[position++] = 0xc1;
|
|
1456
1439
|
pack(twoByte ? -strLength : strLength);
|
|
1457
|
-
return
|
|
1440
|
+
return;
|
|
1458
1441
|
}
|
|
1459
1442
|
let headerSize;
|
|
1460
1443
|
// first we estimate the header size, so we can write to the correct location
|
|
@@ -1528,7 +1511,7 @@
|
|
|
1528
1511
|
} else if (type === 'number') {
|
|
1529
1512
|
if (value >>> 0 === value) {// positive integer, 32-bit or less
|
|
1530
1513
|
// positive uint
|
|
1531
|
-
if (value <
|
|
1514
|
+
if (value < 0x40 || (value < 0x80 && this.useRecords === false)) {
|
|
1532
1515
|
target[position++] = value;
|
|
1533
1516
|
} else if (value < 0x100) {
|
|
1534
1517
|
target[position++] = 0xcc;
|
|
@@ -1567,7 +1550,7 @@
|
|
|
1567
1550
|
// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
1568
1551
|
((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
|
|
1569
1552
|
position += 4;
|
|
1570
|
-
return
|
|
1553
|
+
return;
|
|
1571
1554
|
} else
|
|
1572
1555
|
position--; // move back into position for writing a double
|
|
1573
1556
|
}
|
|
@@ -1590,7 +1573,7 @@
|
|
|
1590
1573
|
target[position++] = 0x70; // "p" for pointer
|
|
1591
1574
|
targetView.setUint32(position, referee.id);
|
|
1592
1575
|
position += 4;
|
|
1593
|
-
return
|
|
1576
|
+
return;
|
|
1594
1577
|
} else
|
|
1595
1578
|
referenceMap.set(value, { offset: position - start });
|
|
1596
1579
|
}
|
|
@@ -1640,7 +1623,7 @@
|
|
|
1640
1623
|
} else {
|
|
1641
1624
|
pack(writeResult);
|
|
1642
1625
|
}
|
|
1643
|
-
return
|
|
1626
|
+
return;
|
|
1644
1627
|
}
|
|
1645
1628
|
let currentTarget = target;
|
|
1646
1629
|
let currentTargetView = targetView;
|
|
@@ -1657,7 +1640,7 @@
|
|
|
1657
1640
|
makeRoom(position);
|
|
1658
1641
|
return {
|
|
1659
1642
|
target, targetView, position: position - size
|
|
1660
|
-
}
|
|
1643
|
+
};
|
|
1661
1644
|
}, pack);
|
|
1662
1645
|
} finally {
|
|
1663
1646
|
// restore current target information (unless already restored)
|
|
@@ -1673,7 +1656,7 @@
|
|
|
1673
1656
|
makeRoom(result.length + position);
|
|
1674
1657
|
position = writeExtensionData(result, target, position, extension.type);
|
|
1675
1658
|
}
|
|
1676
|
-
return
|
|
1659
|
+
return;
|
|
1677
1660
|
}
|
|
1678
1661
|
}
|
|
1679
1662
|
// check isArray after extensions, because extensions can extend Array
|
|
@@ -1685,7 +1668,7 @@
|
|
|
1685
1668
|
const json = value.toJSON();
|
|
1686
1669
|
// if for some reason value.toJSON returns itself it'll loop forever
|
|
1687
1670
|
if (json !== value)
|
|
1688
|
-
return pack(json)
|
|
1671
|
+
return pack(json);
|
|
1689
1672
|
}
|
|
1690
1673
|
|
|
1691
1674
|
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
@@ -1724,7 +1707,7 @@
|
|
|
1724
1707
|
let chunks = [];
|
|
1725
1708
|
while (true) {
|
|
1726
1709
|
chunks.push(value & mask);
|
|
1727
|
-
if ((value >> BigInt(63)) === empty) break
|
|
1710
|
+
if ((value >> BigInt(63)) === empty) break;
|
|
1728
1711
|
value >>= BigInt(64);
|
|
1729
1712
|
}
|
|
1730
1713
|
|
|
@@ -1756,11 +1739,11 @@
|
|
|
1756
1739
|
if (array.length + position > safeEnd)
|
|
1757
1740
|
makeRoom(array.length + position);
|
|
1758
1741
|
position = writeExtensionData(array, target, position, 0x42);
|
|
1759
|
-
return
|
|
1742
|
+
return;
|
|
1760
1743
|
} else {
|
|
1761
1744
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
1762
1745
|
' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
|
|
1763
|
-
' largeBigIntToString to convert to string')
|
|
1746
|
+
' largeBigIntToString to convert to string');
|
|
1764
1747
|
}
|
|
1765
1748
|
}
|
|
1766
1749
|
position += 8;
|
|
@@ -1773,7 +1756,7 @@
|
|
|
1773
1756
|
target[position++] = 0;
|
|
1774
1757
|
}
|
|
1775
1758
|
} else {
|
|
1776
|
-
throw new Error('Unknown type: ' + type)
|
|
1759
|
+
throw new Error('Unknown type: ' + type);
|
|
1777
1760
|
}
|
|
1778
1761
|
};
|
|
1779
1762
|
|
|
@@ -1924,7 +1907,7 @@
|
|
|
1924
1907
|
if (end > 0x1000000) {
|
|
1925
1908
|
// special handling for really large buffers
|
|
1926
1909
|
if ((end - start) > MAX_BUFFER_SIZE)
|
|
1927
|
-
throw new Error('Packed buffer would be larger than maximum buffer size')
|
|
1910
|
+
throw new Error('Packed buffer would be larger than maximum buffer size');
|
|
1928
1911
|
newSize = Math.min(MAX_BUFFER_SIZE,
|
|
1929
1912
|
Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
|
|
1930
1913
|
} else // faster handling for smaller buffers
|
|
@@ -1939,7 +1922,7 @@
|
|
|
1939
1922
|
position -= start;
|
|
1940
1923
|
start = 0;
|
|
1941
1924
|
safeEnd = newBuffer.length - 10;
|
|
1942
|
-
return target = newBuffer
|
|
1925
|
+
return target = newBuffer;
|
|
1943
1926
|
};
|
|
1944
1927
|
const newRecord = (transition, keys, newTransitions) => {
|
|
1945
1928
|
let recordId = structures.nextId;
|
|
@@ -2021,23 +2004,6 @@
|
|
|
2021
2004
|
target[insertionOffset + start] = keysTarget[0];
|
|
2022
2005
|
}
|
|
2023
2006
|
};
|
|
2024
|
-
const writeStruct = (object) => {
|
|
2025
|
-
let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
|
|
2026
|
-
if (notifySharedUpdate)
|
|
2027
|
-
return hasSharedUpdate = true;
|
|
2028
|
-
position = newPosition;
|
|
2029
|
-
let startTarget = target;
|
|
2030
|
-
pack(value);
|
|
2031
|
-
resetStructures();
|
|
2032
|
-
if (startTarget !== target) {
|
|
2033
|
-
return { position, targetView, target }; // indicate the buffer was re-allocated
|
|
2034
|
-
}
|
|
2035
|
-
return position;
|
|
2036
|
-
}, this);
|
|
2037
|
-
if (newPosition === 0) // bail and go to a msgpack object
|
|
2038
|
-
return writeObject(object);
|
|
2039
|
-
position = newPosition;
|
|
2040
|
-
};
|
|
2041
2007
|
}
|
|
2042
2008
|
useBuffer(buffer) {
|
|
2043
2009
|
// this means we are finished using our own buffer and we can write over it safely
|
|
@@ -2055,8 +2021,6 @@
|
|
|
2055
2021
|
clearSharedData() {
|
|
2056
2022
|
if (this.structures)
|
|
2057
2023
|
this.structures = [];
|
|
2058
|
-
if (this.typedStructs)
|
|
2059
|
-
this.typedStructs = [];
|
|
2060
2024
|
}
|
|
2061
2025
|
}
|
|
2062
2026
|
|
|
@@ -2080,7 +2044,7 @@
|
|
|
2080
2044
|
} else if (isNaN(seconds)) {
|
|
2081
2045
|
if (this.onInvalidDate) {
|
|
2082
2046
|
allocateForWrite(0);
|
|
2083
|
-
return pack(this.onInvalidDate())
|
|
2047
|
+
return pack(this.onInvalidDate());
|
|
2084
2048
|
}
|
|
2085
2049
|
// Intentionally invalid timestamp
|
|
2086
2050
|
let { target, targetView, position} = allocateForWrite(3);
|
|
@@ -2101,7 +2065,7 @@
|
|
|
2101
2065
|
pack(set, allocateForWrite, pack) {
|
|
2102
2066
|
if (this.setAsEmptyObject) {
|
|
2103
2067
|
allocateForWrite(0);
|
|
2104
|
-
return pack({})
|
|
2068
|
+
return pack({});
|
|
2105
2069
|
}
|
|
2106
2070
|
let array = Array.from(set);
|
|
2107
2071
|
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
@@ -2209,19 +2173,19 @@
|
|
|
2209
2173
|
switch (length) {
|
|
2210
2174
|
case 1:
|
|
2211
2175
|
target[position++] = 0xd4;
|
|
2212
|
-
break
|
|
2176
|
+
break;
|
|
2213
2177
|
case 2:
|
|
2214
2178
|
target[position++] = 0xd5;
|
|
2215
|
-
break
|
|
2179
|
+
break;
|
|
2216
2180
|
case 4:
|
|
2217
2181
|
target[position++] = 0xd6;
|
|
2218
|
-
break
|
|
2182
|
+
break;
|
|
2219
2183
|
case 8:
|
|
2220
2184
|
target[position++] = 0xd7;
|
|
2221
|
-
break
|
|
2185
|
+
break;
|
|
2222
2186
|
case 16:
|
|
2223
2187
|
target[position++] = 0xd8;
|
|
2224
|
-
break
|
|
2188
|
+
break;
|
|
2225
2189
|
default:
|
|
2226
2190
|
if (length < 0x100) {
|
|
2227
2191
|
target[position++] = 0xc7;
|
|
@@ -2241,7 +2205,7 @@
|
|
|
2241
2205
|
target[position++] = type;
|
|
2242
2206
|
target.set(result, position);
|
|
2243
2207
|
position += length;
|
|
2244
|
-
return position
|
|
2208
|
+
return position;
|
|
2245
2209
|
}
|
|
2246
2210
|
|
|
2247
2211
|
function insertIds(serialized, idsToInsert) {
|
|
@@ -2263,7 +2227,7 @@
|
|
|
2263
2227
|
serialized[position++] = id & 0xff;
|
|
2264
2228
|
lastEnd = offset;
|
|
2265
2229
|
}
|
|
2266
|
-
return serialized
|
|
2230
|
+
return serialized;
|
|
2267
2231
|
}
|
|
2268
2232
|
|
|
2269
2233
|
function writeBundles(start, pack, incrementPosition) {
|
|
@@ -2280,9 +2244,9 @@
|
|
|
2280
2244
|
function addExtension(extension) {
|
|
2281
2245
|
if (extension.Class) {
|
|
2282
2246
|
if (!extension.pack && !extension.write)
|
|
2283
|
-
throw new Error('Extension has no pack or write function')
|
|
2247
|
+
throw new Error('Extension has no pack or write function');
|
|
2284
2248
|
if (extension.pack && !extension.type)
|
|
2285
|
-
throw new Error('Extension has no type (numeric code to identify the extension)')
|
|
2249
|
+
throw new Error('Extension has no type (numeric code to identify the extension)');
|
|
2286
2250
|
extensionClasses.unshift(extension.Class);
|
|
2287
2251
|
extensions.unshift(extension);
|
|
2288
2252
|
}
|
|
@@ -2295,7 +2259,7 @@
|
|
|
2295
2259
|
packr._mergeStructures(existingStructures);
|
|
2296
2260
|
return compatible;
|
|
2297
2261
|
};
|
|
2298
|
-
return structures
|
|
2262
|
+
return structures;
|
|
2299
2263
|
}
|
|
2300
2264
|
|
|
2301
2265
|
let defaultPackr = new Packr({ useRecords: false });
|
|
@@ -2316,13 +2280,13 @@
|
|
|
2316
2280
|
*/
|
|
2317
2281
|
function packIter (objectIterator, options = {}) {
|
|
2318
2282
|
if (!objectIterator || typeof objectIterator !== 'object') {
|
|
2319
|
-
throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
|
|
2283
|
+
throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
|
|
2320
2284
|
} else if (typeof objectIterator[Symbol.iterator] === 'function') {
|
|
2321
|
-
return packIterSync(objectIterator, options)
|
|
2285
|
+
return packIterSync(objectIterator, options);
|
|
2322
2286
|
} else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
|
|
2323
|
-
return packIterAsync(objectIterator, options)
|
|
2287
|
+
return packIterAsync(objectIterator, options);
|
|
2324
2288
|
} else {
|
|
2325
|
-
throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
|
|
2289
|
+
throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
|
|
2326
2290
|
}
|
|
2327
2291
|
}
|
|
2328
2292
|
|
|
@@ -2349,7 +2313,7 @@
|
|
|
2349
2313
|
*/
|
|
2350
2314
|
function unpackIter (bufferIterator, options = {}) {
|
|
2351
2315
|
if (!bufferIterator || typeof bufferIterator !== 'object') {
|
|
2352
|
-
throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
|
|
2316
|
+
throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
|
|
2353
2317
|
}
|
|
2354
2318
|
|
|
2355
2319
|
const unpackr = new Unpackr(options);
|
|
@@ -2369,10 +2333,10 @@
|
|
|
2369
2333
|
incomplete = chunk.slice(err.lastPosition);
|
|
2370
2334
|
yields = err.values;
|
|
2371
2335
|
} else {
|
|
2372
|
-
throw err
|
|
2336
|
+
throw err;
|
|
2373
2337
|
}
|
|
2374
2338
|
}
|
|
2375
|
-
return yields
|
|
2339
|
+
return yields;
|
|
2376
2340
|
};
|
|
2377
2341
|
|
|
2378
2342
|
if (typeof bufferIterator[Symbol.iterator] === 'function') {
|
|
@@ -2380,13 +2344,13 @@
|
|
|
2380
2344
|
for (const value of bufferIterator) {
|
|
2381
2345
|
yield * parser(value);
|
|
2382
2346
|
}
|
|
2383
|
-
})()
|
|
2347
|
+
})();
|
|
2384
2348
|
} else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
|
|
2385
2349
|
return (async function * iter () {
|
|
2386
2350
|
for await (const value of bufferIterator) {
|
|
2387
2351
|
yield * parser(value);
|
|
2388
2352
|
}
|
|
2389
|
-
})()
|
|
2353
|
+
})();
|
|
2390
2354
|
}
|
|
2391
2355
|
}
|
|
2392
2356
|
const decodeIter = unpackIter;
|