sandboxedjs 0.1.83 → 0.1.85

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.
@@ -1,6 +1,6 @@
1
- import { V as Vfs, C as Cred, a as VirtualTcpNetwork } from './contracts-DNkSvBCM.cjs';
2
- export { m as ROOT_CRED, v as makeCred } from './contracts-DNkSvBCM.cjs';
3
- export { M as MemoryVolume } from './memory-volume-n-LY8Vdv.cjs';
1
+ import { V as Vfs, C as Cred, a as VirtualTcpNetwork } from './contracts-BkWBTH8E.cjs';
2
+ export { m as ROOT_CRED, v as makeCred } from './contracts-BkWBTH8E.cjs';
3
+ export { M as MemoryVolume } from './memory-volume-DCm-DiXH.cjs';
4
4
 
5
5
  /**
6
6
  * Open-file descriptions: the thing a descriptor points *at*.
@@ -1,6 +1,6 @@
1
- import { V as Vfs, C as Cred, a as VirtualTcpNetwork } from './contracts-DNkSvBCM.js';
2
- export { m as ROOT_CRED, v as makeCred } from './contracts-DNkSvBCM.js';
3
- export { M as MemoryVolume } from './memory-volume-D4FLjyEU.js';
1
+ import { V as Vfs, C as Cred, a as VirtualTcpNetwork } from './contracts-BkWBTH8E.js';
2
+ export { m as ROOT_CRED, v as makeCred } from './contracts-BkWBTH8E.js';
3
+ export { M as MemoryVolume } from './memory-volume-DJA-vFYW.js';
4
4
 
5
5
  /**
6
6
  * Open-file descriptions: the thing a descriptor points *at*.
@@ -2949,6 +2949,7 @@ var MemoryStat = class {
2949
2949
  }
2950
2950
  };
2951
2951
  var encoder2 = new TextEncoder();
2952
+ var appendCapacity = /* @__PURE__ */ new WeakMap();
2952
2953
  var MemoryVolume = class {
2953
2954
  entries = /* @__PURE__ */ new Map();
2954
2955
  nextIno = 2;
@@ -2983,10 +2984,23 @@ var MemoryVolume = class {
2983
2984
  const current = this.entries.get(key);
2984
2985
  if (!current) return this.writeFileSync(key, bytes);
2985
2986
  if (current.kind !== "file") throw new VolumeError(current.kind === "directory" ? "EISDIR" : "EINVAL", "open", key);
2986
- const next = new Uint8Array(current.data.length + bytes.length);
2987
- next.set(current.data);
2988
- next.set(bytes, current.data.length);
2989
- current.data = next;
2987
+ const length = current.data.length;
2988
+ const needed = length + bytes.length;
2989
+ const backing = current.data.buffer;
2990
+ const ownsTail = current.data.byteOffset === 0 && backing instanceof ArrayBuffer && backing.byteLength >= needed && appendCapacity.get(current) === backing;
2991
+ if (ownsTail) {
2992
+ const grown = new Uint8Array(backing, 0, needed);
2993
+ grown.set(bytes, length);
2994
+ current.data = grown;
2995
+ } else {
2996
+ const capacity = Math.max(needed, length * 2, 64 * 1024);
2997
+ const buffer = new ArrayBuffer(capacity);
2998
+ const grown = new Uint8Array(buffer, 0, needed);
2999
+ grown.set(current.data);
3000
+ grown.set(bytes, length);
3001
+ current.data = grown;
3002
+ appendCapacity.set(current, buffer);
3003
+ }
2990
3004
  this.touchChanged(current, true);
2991
3005
  }
2992
3006
  readdirSync(path) {