cbor-x 1.5.0 → 1.5.2
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 +1 -0
- package/decode.js +33 -17
- package/dist/decode-no-eval.cjs +33 -17
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +52 -28
- 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 +52 -28
- 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 +52 -28
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +19 -1
- package/dist/test.js.map +1 -1
- package/encode.js +15 -7
- package/index.d.ts +1 -0
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -357,13 +357,28 @@
|
|
|
357
357
|
return structure.read()
|
|
358
358
|
}
|
|
359
359
|
if (token < 0x10000) {
|
|
360
|
-
if (token == RECORD_INLINE_ID) // we do a special check for this so that we can keep the
|
|
361
|
-
|
|
360
|
+
if (token == RECORD_INLINE_ID) { // we do a special check for this so that we can keep the
|
|
361
|
+
// currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
|
|
362
|
+
let length = readJustLength();
|
|
363
|
+
let id = read();
|
|
364
|
+
let structure = read();
|
|
365
|
+
recordDefinition(id, structure);
|
|
366
|
+
let object = {};
|
|
367
|
+
if (currentDecoder.keyMap) for (let i = 2; i < length; i++) {
|
|
368
|
+
let key = currentDecoder.decodeKey(structure[i - 2]);
|
|
369
|
+
object[safeKey(key)] = read();
|
|
370
|
+
}
|
|
371
|
+
else for (let i = 2; i < length; i++) {
|
|
372
|
+
let key = structure[i - 2];
|
|
373
|
+
object[safeKey(key)] = read();
|
|
374
|
+
}
|
|
375
|
+
return object
|
|
376
|
+
}
|
|
362
377
|
else if (token == RECORD_DEFINITIONS_ID) {
|
|
363
378
|
let length = readJustLength();
|
|
364
379
|
let id = read();
|
|
365
380
|
for (let i = 2; i < length; i++) {
|
|
366
|
-
recordDefinition(
|
|
381
|
+
recordDefinition(id++, read());
|
|
367
382
|
}
|
|
368
383
|
return read()
|
|
369
384
|
} else if (token == BUNDLED_STRINGS_ID) {
|
|
@@ -760,9 +775,8 @@
|
|
|
760
775
|
};
|
|
761
776
|
|
|
762
777
|
// the registration of the record definition extension
|
|
763
|
-
const recordDefinition = (
|
|
764
|
-
|
|
765
|
-
let structure = definition[1];
|
|
778
|
+
const recordDefinition = (id, structure) => {
|
|
779
|
+
id = id - 0xe000;
|
|
766
780
|
let existingStructure = currentStructures[id];
|
|
767
781
|
if (existingStructure && existingStructure.isShared) {
|
|
768
782
|
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
|
|
@@ -770,18 +784,18 @@
|
|
|
770
784
|
currentStructures[id] = structure;
|
|
771
785
|
|
|
772
786
|
structure.read = createStructureReader(structure);
|
|
787
|
+
};
|
|
788
|
+
currentExtensions[LEGACY_RECORD_INLINE_ID] = (data) => {
|
|
789
|
+
let length = data.length;
|
|
790
|
+
let structure = data[1];
|
|
791
|
+
recordDefinition(data[0], structure);
|
|
773
792
|
let object = {};
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
else for (let i = 2,l = definition.length; i < l; i++) {
|
|
779
|
-
let key = structure[i - 2];
|
|
780
|
-
object[safeKey(key)] = definition[i];
|
|
781
|
-
}
|
|
793
|
+
for (let i = 2; i < length; i++) {
|
|
794
|
+
let key = structure[i - 2];
|
|
795
|
+
object[safeKey(key)] = data[i];
|
|
796
|
+
}
|
|
782
797
|
return object
|
|
783
798
|
};
|
|
784
|
-
currentExtensions[LEGACY_RECORD_INLINE_ID] = recordDefinition;
|
|
785
799
|
currentExtensions[14] = (value) => {
|
|
786
800
|
if (bundledStrings$1)
|
|
787
801
|
return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 += value)
|
|
@@ -931,9 +945,11 @@
|
|
|
931
945
|
}
|
|
932
946
|
function registerTypedArray(TypedArray, tag) {
|
|
933
947
|
let dvMethod = 'get' + TypedArray.name.slice(0, -5);
|
|
934
|
-
|
|
948
|
+
let bytesPerElement;
|
|
949
|
+
if (typeof TypedArray === 'function')
|
|
950
|
+
bytesPerElement = TypedArray.BYTES_PER_ELEMENT;
|
|
951
|
+
else
|
|
935
952
|
TypedArray = null;
|
|
936
|
-
let bytesPerElement = TypedArray.BYTES_PER_ELEMENT;
|
|
937
953
|
for (let littleEndian = 0; littleEndian < 2; littleEndian++) {
|
|
938
954
|
if (!littleEndian && bytesPerElement == 1)
|
|
939
955
|
continue
|
|
@@ -1076,10 +1092,10 @@
|
|
|
1076
1092
|
textEncoder = new TextEncoder();
|
|
1077
1093
|
} catch (error) {}
|
|
1078
1094
|
let extensions, extensionClasses;
|
|
1079
|
-
const
|
|
1080
|
-
const
|
|
1081
|
-
const
|
|
1082
|
-
const
|
|
1095
|
+
const Buffer$1 = globalThis.Buffer;
|
|
1096
|
+
const hasNodeBuffer = typeof Buffer$1 !== 'undefined';
|
|
1097
|
+
const ByteArrayAllocate = hasNodeBuffer ? Buffer$1.allocUnsafeSlow : Uint8Array;
|
|
1098
|
+
const ByteArray = hasNodeBuffer ? Buffer$1 : Uint8Array;
|
|
1083
1099
|
const MAX_STRUCTURES = 0x100;
|
|
1084
1100
|
const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
|
|
1085
1101
|
let throwOnIterable;
|
|
@@ -1467,7 +1483,7 @@
|
|
|
1467
1483
|
}
|
|
1468
1484
|
position += length;
|
|
1469
1485
|
} else if (type === 'number') {
|
|
1470
|
-
if (value >>> 0 === value) {// positive integer, 32-bit or less
|
|
1486
|
+
if (!this.alwaysUseFloat && value >>> 0 === value) {// positive integer, 32-bit or less
|
|
1471
1487
|
// positive uint
|
|
1472
1488
|
if (value < 0x18) {
|
|
1473
1489
|
target[position++] = value;
|
|
@@ -1483,7 +1499,7 @@
|
|
|
1483
1499
|
targetView.setUint32(position, value);
|
|
1484
1500
|
position += 4;
|
|
1485
1501
|
}
|
|
1486
|
-
} else if (value >> 0 === value) { // negative integer
|
|
1502
|
+
} else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer
|
|
1487
1503
|
if (value >= -0x18) {
|
|
1488
1504
|
target[position++] = 0x1f - value;
|
|
1489
1505
|
} else if (value >= -0x100) {
|
|
@@ -1622,7 +1638,7 @@
|
|
|
1622
1638
|
target[position++] = 0xff; // stop-code
|
|
1623
1639
|
return
|
|
1624
1640
|
}
|
|
1625
|
-
if (value[Symbol.asyncIterator] ||
|
|
1641
|
+
if (value[Symbol.asyncIterator] || isBlob(value)) {
|
|
1626
1642
|
let error = new Error('Iterable/blob should be serialized as iterator');
|
|
1627
1643
|
error.iteratorNotHandled = true;
|
|
1628
1644
|
throw error;
|
|
@@ -1856,7 +1872,8 @@
|
|
|
1856
1872
|
} else encode(value);
|
|
1857
1873
|
}
|
|
1858
1874
|
} else if (constructor === Array) {
|
|
1859
|
-
|
|
1875
|
+
let length = object.length;
|
|
1876
|
+
writeArrayHeader(length);
|
|
1860
1877
|
for (let i = 0; i < length; i++) {
|
|
1861
1878
|
let value = object[i];
|
|
1862
1879
|
if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
|
|
@@ -1877,7 +1894,7 @@
|
|
|
1877
1894
|
} else encode(value);
|
|
1878
1895
|
}
|
|
1879
1896
|
target[position++] = 0xff; // stop byte
|
|
1880
|
-
} else if (
|
|
1897
|
+
} else if (isBlob(object)){
|
|
1881
1898
|
writeEntityLength(object.size, 0x40); // encode as binary data
|
|
1882
1899
|
yield target.subarray(start, position);
|
|
1883
1900
|
yield object; // directly return blobs, they have to be encoded asynchronously
|
|
@@ -1934,7 +1951,7 @@
|
|
|
1934
1951
|
let constructor = encodedValue.constructor;
|
|
1935
1952
|
if (constructor === ByteArray || constructor === Uint8Array)
|
|
1936
1953
|
yield encodedValue;
|
|
1937
|
-
else if (
|
|
1954
|
+
else if (isBlob(encodedValue)) {
|
|
1938
1955
|
let reader = encodedValue.stream().getReader();
|
|
1939
1956
|
let next;
|
|
1940
1957
|
while (!(next = await reader.read()).done) {
|
|
@@ -2029,6 +2046,13 @@
|
|
|
2029
2046
|
}
|
|
2030
2047
|
}
|
|
2031
2048
|
|
|
2049
|
+
const BlobConstructor = typeof Blob === 'undefined' ? function(){} : Blob;
|
|
2050
|
+
function isBlob(object) {
|
|
2051
|
+
if (object instanceof BlobConstructor)
|
|
2052
|
+
return true;
|
|
2053
|
+
let tag = object[Symbol.toStringTag];
|
|
2054
|
+
return tag === 'Blob' || tag === 'File';
|
|
2055
|
+
}
|
|
2032
2056
|
function findRepetitiveStrings(value, packedValues) {
|
|
2033
2057
|
switch(typeof value) {
|
|
2034
2058
|
case 'string':
|
|
@@ -2187,7 +2211,7 @@
|
|
|
2187
2211
|
let length = typedArray.byteLength;
|
|
2188
2212
|
let offset = typedArray.byteOffset || 0;
|
|
2189
2213
|
let buffer = typedArray.buffer || typedArray;
|
|
2190
|
-
encode(hasNodeBuffer ? Buffer.from(buffer, offset, length) :
|
|
2214
|
+
encode(hasNodeBuffer ? Buffer$1.from(buffer, offset, length) :
|
|
2191
2215
|
new Uint8Array(buffer, offset, length));
|
|
2192
2216
|
}
|
|
2193
2217
|
}
|