bun-memory 1.1.41 → 1.1.42

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/structs/Memory.ts +12 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-memory",
3
- "version": "1.1.41",
3
+ "version": "1.1.42",
4
4
  "author": "Stev Peifer <stev@bell.net>",
5
5
  "repository": {
6
6
  "type": "git",
package/structs/Memory.ts CHANGED
@@ -1796,22 +1796,24 @@ class Memory {
1796
1796
  /**
1797
1797
  * Reads or writes a generic UtlVector as raw bytes (no typing).
1798
1798
  * Pass elementSize (bytes per element) so we can set/read the header count.
1799
- * Optionally provide countOverride to read a specific number of elements regardless of the stored size.
1800
1799
  * @example
1801
1800
  * ```ts
1802
- * const bytes = cs2.utlVectorRaw(0x1234n, 0x14, 5); // read 5 elements of size 0x14 (total 0x78 bytes)
1803
- * cs2.utlVectorRaw(0x1234n, 0x14); // read size from header
1801
+ * const bytes = cs2.utlVectorRaw(0x1234n, 0x14); // read size*elementSize bytes
1804
1802
  * cs2.utlVectorRaw(0x1234n, 0x14, new Uint8Array([...])); // write
1805
1803
  * ```
1806
1804
  */
1807
1805
  public utlVectorRaw(address: bigint, elementSize: number): Uint8Array;
1808
- public utlVectorRaw(address: bigint, elementSize: number, count: number): Uint8Array;
1809
1806
  public utlVectorRaw(address: bigint, elementSize: number, values: Uint8Array, force?: boolean): this;
1810
- public utlVectorRaw(address: bigint, elementSize: number, countOrValues?: number | Uint8Array, force?: boolean): Uint8Array | this {
1807
+ public utlVectorRaw(address: bigint, elementSize: number, values?: Uint8Array, force?: boolean): Uint8Array | this {
1811
1808
  const elementsPtr = this.u64(address + 0x08n);
1812
1809
 
1813
- if (countOrValues === undefined || typeof countOrValues === 'number') {
1814
- const count = countOrValues === undefined ? this.u32(address) : countOrValues;
1810
+ if (values === undefined) {
1811
+ const count = this.u32(address);
1812
+
1813
+ if (count === 0 || elementsPtr === 0n) {
1814
+ return new Uint8Array(0);
1815
+ }
1816
+
1815
1817
  const byteLength = count * elementSize;
1816
1818
  const scratch = new Uint8Array(byteLength);
1817
1819
 
@@ -1820,15 +1822,15 @@ class Memory {
1820
1822
  return scratch;
1821
1823
  }
1822
1824
 
1823
- if (countOrValues.byteLength % elementSize !== 0) {
1825
+ if (values.byteLength % elementSize !== 0) {
1824
1826
  throw new RangeError('values length must be a multiple of elementSize');
1825
1827
  }
1826
1828
 
1827
- const count = countOrValues.byteLength / elementSize;
1829
+ const count = values.byteLength / elementSize;
1828
1830
 
1829
1831
  this.u32(address, count, force);
1830
1832
 
1831
- void this.write(elementsPtr, countOrValues, force);
1833
+ void this.write(elementsPtr, values, force);
1832
1834
 
1833
1835
  return this;
1834
1836
  }