msgpackr 1.9.1 → 1.9.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 +12 -0
- package/dist/index-no-eval.cjs +15 -5
- 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 +15 -5
- 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 +15 -5
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +39 -6
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +10 -3
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/pack.d.cts +1 -0
- package/pack.js +5 -2
- package/package.json +14 -6
- package/unpack.d.cts +2 -0
- package/unpack.js +10 -3
package/dist/node.cjs
CHANGED
|
@@ -122,10 +122,10 @@ class Unpackr {
|
|
|
122
122
|
let size = source.length;
|
|
123
123
|
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
|
|
124
124
|
if (forEach) {
|
|
125
|
-
if (forEach(value) === false) return;
|
|
125
|
+
if (forEach(value, lastPosition, position$1) === false) return;
|
|
126
126
|
while(position$1 < size) {
|
|
127
127
|
lastPosition = position$1;
|
|
128
|
-
if (forEach(checkedRead()) === false) {
|
|
128
|
+
if (forEach(checkedRead(), lastPosition, position$1) === false) {
|
|
129
129
|
return
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -199,6 +199,10 @@ function checkedRead(options) {
|
|
|
199
199
|
position$1 = bundledStrings$1.postBundlePosition;
|
|
200
200
|
bundledStrings$1 = null;
|
|
201
201
|
}
|
|
202
|
+
if (sequentialMode)
|
|
203
|
+
// we only need to restore the structures if there was an error, but if we completed a read,
|
|
204
|
+
// we can clear this out and keep the structures we read
|
|
205
|
+
currentStructures.restoreStructures = null;
|
|
202
206
|
|
|
203
207
|
if (position$1 == srcEnd) {
|
|
204
208
|
// finished reading this source, cleanup references
|
|
@@ -971,7 +975,10 @@ const recordDefinition = (id, highByte) => {
|
|
|
971
975
|
structure.highByte = highByte;
|
|
972
976
|
}
|
|
973
977
|
let existingStructure = currentStructures[id];
|
|
974
|
-
|
|
978
|
+
// If it is a shared structure, we need to restore any changes after reading.
|
|
979
|
+
// Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
|
|
980
|
+
// to the state prior to an incomplete read in order to properly resume.
|
|
981
|
+
if (existingStructure && (existingStructure.isShared || sequentialMode)) {
|
|
975
982
|
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
|
|
976
983
|
}
|
|
977
984
|
currentStructures[id] = structure;
|
|
@@ -1319,7 +1326,7 @@ class Packr extends Unpackr {
|
|
|
1319
1326
|
if (serializationsSinceTransitionRebuild < 10)
|
|
1320
1327
|
serializationsSinceTransitionRebuild++;
|
|
1321
1328
|
let sharedLength = structures.sharedLength || 0;
|
|
1322
|
-
if (structures.length > sharedLength)
|
|
1329
|
+
if (structures.length > sharedLength && !isSequential)
|
|
1323
1330
|
structures.length = sharedLength;
|
|
1324
1331
|
if (transitionsCount > 10000) {
|
|
1325
1332
|
// force a rebuild occasionally after a lot of transitions so it can get cleaned up
|
|
@@ -1954,7 +1961,10 @@ extensions = [{
|
|
|
1954
1961
|
}
|
|
1955
1962
|
}, {
|
|
1956
1963
|
pack(set, allocateForWrite, pack) {
|
|
1957
|
-
if (this.setAsEmptyObject)
|
|
1964
|
+
if (this.setAsEmptyObject) {
|
|
1965
|
+
allocateForWrite(0);
|
|
1966
|
+
return pack({})
|
|
1967
|
+
}
|
|
1958
1968
|
let array = Array.from(set);
|
|
1959
1969
|
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1960
1970
|
if (this.moreTypes) {
|