cbor-x 1.5.0 → 1.5.1
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/decode.js +29 -15
- package/dist/decode-no-eval.cjs +29 -15
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +46 -24
- 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 +46 -24
- 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 +46 -24
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +9 -1
- package/dist/test.js.map +1 -1
- package/encode.js +13 -5
- package/package.json +4 -1
package/dist/node.cjs
CHANGED
|
@@ -361,13 +361,28 @@ function read() {
|
|
|
361
361
|
return structure.read()
|
|
362
362
|
}
|
|
363
363
|
if (token < 0x10000) {
|
|
364
|
-
if (token == RECORD_INLINE_ID) // we do a special check for this so that we can keep the
|
|
365
|
-
|
|
364
|
+
if (token == RECORD_INLINE_ID) { // we do a special check for this so that we can keep the
|
|
365
|
+
// currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
|
|
366
|
+
let length = readJustLength();
|
|
367
|
+
let id = read();
|
|
368
|
+
let structure = read();
|
|
369
|
+
recordDefinition(id, structure);
|
|
370
|
+
let object = {};
|
|
371
|
+
if (currentDecoder.keyMap) for (let i = 2; i < length; i++) {
|
|
372
|
+
let key = currentDecoder.decodeKey(structure[i - 2]);
|
|
373
|
+
object[safeKey(key)] = read();
|
|
374
|
+
}
|
|
375
|
+
else for (let i = 2; i < length; i++) {
|
|
376
|
+
let key = structure[i - 2];
|
|
377
|
+
object[safeKey(key)] = read();
|
|
378
|
+
}
|
|
379
|
+
return object
|
|
380
|
+
}
|
|
366
381
|
else if (token == RECORD_DEFINITIONS_ID) {
|
|
367
382
|
let length = readJustLength();
|
|
368
383
|
let id = read();
|
|
369
384
|
for (let i = 2; i < length; i++) {
|
|
370
|
-
recordDefinition(
|
|
385
|
+
recordDefinition(id++, read());
|
|
371
386
|
}
|
|
372
387
|
return read()
|
|
373
388
|
} else if (token == BUNDLED_STRINGS_ID) {
|
|
@@ -799,9 +814,8 @@ currentExtensions[5] = (fraction) => {
|
|
|
799
814
|
};
|
|
800
815
|
|
|
801
816
|
// the registration of the record definition extension
|
|
802
|
-
const recordDefinition = (
|
|
803
|
-
|
|
804
|
-
let structure = definition[1];
|
|
817
|
+
const recordDefinition = (id, structure) => {
|
|
818
|
+
id = id - 0xe000;
|
|
805
819
|
let existingStructure = currentStructures[id];
|
|
806
820
|
if (existingStructure && existingStructure.isShared) {
|
|
807
821
|
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
|
|
@@ -809,18 +823,18 @@ const recordDefinition = (definition) => {
|
|
|
809
823
|
currentStructures[id] = structure;
|
|
810
824
|
|
|
811
825
|
structure.read = createStructureReader(structure);
|
|
826
|
+
};
|
|
827
|
+
currentExtensions[LEGACY_RECORD_INLINE_ID] = (data) => {
|
|
828
|
+
let length = data.length;
|
|
829
|
+
let structure = data[1];
|
|
830
|
+
recordDefinition(data[0], structure);
|
|
812
831
|
let object = {};
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
else for (let i = 2,l = definition.length; i < l; i++) {
|
|
818
|
-
let key = structure[i - 2];
|
|
819
|
-
object[safeKey(key)] = definition[i];
|
|
820
|
-
}
|
|
832
|
+
for (let i = 2; i < length; i++) {
|
|
833
|
+
let key = structure[i - 2];
|
|
834
|
+
object[safeKey(key)] = data[i];
|
|
835
|
+
}
|
|
821
836
|
return object
|
|
822
837
|
};
|
|
823
|
-
currentExtensions[LEGACY_RECORD_INLINE_ID] = recordDefinition;
|
|
824
838
|
currentExtensions[14] = (value) => {
|
|
825
839
|
if (bundledStrings$1)
|
|
826
840
|
return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 += value)
|
|
@@ -1119,10 +1133,10 @@ try {
|
|
|
1119
1133
|
textEncoder = new TextEncoder();
|
|
1120
1134
|
} catch (error) {}
|
|
1121
1135
|
let extensions, extensionClasses;
|
|
1122
|
-
const
|
|
1123
|
-
const
|
|
1124
|
-
const
|
|
1125
|
-
const
|
|
1136
|
+
const Buffer$1 = globalThis.Buffer;
|
|
1137
|
+
const hasNodeBuffer = typeof Buffer$1 !== 'undefined';
|
|
1138
|
+
const ByteArrayAllocate = hasNodeBuffer ? Buffer$1.allocUnsafeSlow : Uint8Array;
|
|
1139
|
+
const ByteArray = hasNodeBuffer ? Buffer$1 : Uint8Array;
|
|
1126
1140
|
const MAX_STRUCTURES = 0x100;
|
|
1127
1141
|
const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
|
|
1128
1142
|
let throwOnIterable;
|
|
@@ -1665,7 +1679,7 @@ class Encoder extends Decoder {
|
|
|
1665
1679
|
target[position++] = 0xff; // stop-code
|
|
1666
1680
|
return
|
|
1667
1681
|
}
|
|
1668
|
-
if (value[Symbol.asyncIterator] ||
|
|
1682
|
+
if (value[Symbol.asyncIterator] || isBlob(value)) {
|
|
1669
1683
|
let error = new Error('Iterable/blob should be serialized as iterator');
|
|
1670
1684
|
error.iteratorNotHandled = true;
|
|
1671
1685
|
throw error;
|
|
@@ -1899,7 +1913,8 @@ class Encoder extends Decoder {
|
|
|
1899
1913
|
} else encode(value);
|
|
1900
1914
|
}
|
|
1901
1915
|
} else if (constructor === Array) {
|
|
1902
|
-
|
|
1916
|
+
let length = object.length;
|
|
1917
|
+
writeArrayHeader(length);
|
|
1903
1918
|
for (let i = 0; i < length; i++) {
|
|
1904
1919
|
let value = object[i];
|
|
1905
1920
|
if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
|
|
@@ -1920,7 +1935,7 @@ class Encoder extends Decoder {
|
|
|
1920
1935
|
} else encode(value);
|
|
1921
1936
|
}
|
|
1922
1937
|
target[position++] = 0xff; // stop byte
|
|
1923
|
-
} else if (
|
|
1938
|
+
} else if (isBlob(object)){
|
|
1924
1939
|
writeEntityLength(object.size, 0x40); // encode as binary data
|
|
1925
1940
|
yield target.subarray(start, position);
|
|
1926
1941
|
yield object; // directly return blobs, they have to be encoded asynchronously
|
|
@@ -1977,7 +1992,7 @@ class Encoder extends Decoder {
|
|
|
1977
1992
|
let constructor = encodedValue.constructor;
|
|
1978
1993
|
if (constructor === ByteArray || constructor === Uint8Array)
|
|
1979
1994
|
yield encodedValue;
|
|
1980
|
-
else if (
|
|
1995
|
+
else if (isBlob(encodedValue)) {
|
|
1981
1996
|
let reader = encodedValue.stream().getReader();
|
|
1982
1997
|
let next;
|
|
1983
1998
|
while (!(next = await reader.read()).done) {
|
|
@@ -2072,6 +2087,13 @@ function writeArrayHeader(length) {
|
|
|
2072
2087
|
}
|
|
2073
2088
|
}
|
|
2074
2089
|
|
|
2090
|
+
const BlobConstructor = typeof Blob === 'undefined' ? function(){} : Blob;
|
|
2091
|
+
function isBlob(object) {
|
|
2092
|
+
if (object instanceof BlobConstructor)
|
|
2093
|
+
return true;
|
|
2094
|
+
let tag = object[Symbol.toStringTag];
|
|
2095
|
+
return tag === 'Blob' || tag === 'File';
|
|
2096
|
+
}
|
|
2075
2097
|
function findRepetitiveStrings(value, packedValues) {
|
|
2076
2098
|
switch(typeof value) {
|
|
2077
2099
|
case 'string':
|
|
@@ -2230,7 +2252,7 @@ function typedArrayEncoder(tag, size) {
|
|
|
2230
2252
|
let length = typedArray.byteLength;
|
|
2231
2253
|
let offset = typedArray.byteOffset || 0;
|
|
2232
2254
|
let buffer = typedArray.buffer || typedArray;
|
|
2233
|
-
encode(hasNodeBuffer ? Buffer.from(buffer, offset, length) :
|
|
2255
|
+
encode(hasNodeBuffer ? Buffer$1.from(buffer, offset, length) :
|
|
2234
2256
|
new Uint8Array(buffer, offset, length));
|
|
2235
2257
|
}
|
|
2236
2258
|
}
|