msgpackr 1.7.0 → 1.7.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/dist/node.cjs CHANGED
@@ -196,7 +196,7 @@ function checkedRead(options) {
196
196
 
197
197
  if (position == srcEnd) {
198
198
  // finished reading this source, cleanup references
199
- if (currentStructures?.restoreStructures)
199
+ if (currentStructures && currentStructures.restoreStructures)
200
200
  restoreStructures();
201
201
  currentStructures = null;
202
202
  src = null;
@@ -211,7 +211,7 @@ function checkedRead(options) {
211
211
  // else more to read, but we are reading sequentially, so don't clear source yet
212
212
  return result
213
213
  } catch(error) {
214
- if (currentStructures?.restoreStructures)
214
+ if (currentStructures && currentStructures.restoreStructures)
215
215
  restoreStructures();
216
216
  clearSource();
217
217
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
@@ -1254,12 +1254,11 @@ class Packr extends Unpackr {
1254
1254
  writeStruct(value);
1255
1255
  else
1256
1256
  pack(value);
1257
- if (bundledStrings$1) {
1258
- writeBundles(start, pack);
1259
- }
1260
- packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1261
1257
  if (referenceMap && referenceMap.idsToInsert) {
1262
- position$1 += referenceMap.idsToInsert.length * 6;
1258
+ let incrementPosition = referenceMap.idsToInsert.length * 6;
1259
+ if (bundledStrings$1)
1260
+ writeBundles(start, pack, incrementPosition);
1261
+ position$1 += incrementPosition;
1263
1262
  if (position$1 > safeEnd)
1264
1263
  makeRoom(position$1);
1265
1264
  packr.offset = position$1;
@@ -1267,6 +1266,9 @@ class Packr extends Unpackr {
1267
1266
  referenceMap = null;
1268
1267
  return serialized
1269
1268
  }
1269
+ if (bundledStrings$1)
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
1270
1272
  if (encodeOptions & REUSE_BUFFER_MODE) {
1271
1273
  target.start = start;
1272
1274
  target.end = position$1;
@@ -2045,9 +2047,9 @@ function insertIds(serialized, idsToInsert) {
2045
2047
  return serialized
2046
2048
  }
2047
2049
 
2048
- function writeBundles(start, pack) {
2050
+ function writeBundles(start, pack, incrementPosition) {
2049
2051
  if (bundledStrings$1.length > 0) {
2050
- targetView.setUint32(bundledStrings$1.position + start, position$1 - bundledStrings$1.position - start);
2052
+ targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
2051
2053
  let writeStrings = bundledStrings$1;
2052
2054
  bundledStrings$1 = null;
2053
2055
  pack(writeStrings[0]);
@@ -2540,7 +2542,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2540
2542
  case 27: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16) + (src[position++] << 24); break;
2541
2543
  }
2542
2544
  }
2543
- let structure = unpackr.typedStructs?.[recordId];
2545
+ let structure = unpackr.typedStructs && unpackr.typedStructs[recordId];
2544
2546
  if (!structure) {
2545
2547
  // copy src buffer because getStructures will override it
2546
2548
  src = Uint8Array.prototype.slice.call(src, position, srcEnd);
@@ -2832,7 +2834,7 @@ function prepareStructures$1(structures, packr) {
2832
2834
  packr._mergeStructures(existing);
2833
2835
  return compatible;
2834
2836
  };
2835
- packr.lastTypedStructuresLength = packr.typedStructs?.length;
2837
+ packr.lastTypedStructuresLength = packr.typedStructs && packr.typedStructs.length;
2836
2838
  return structures;
2837
2839
  }
2838
2840