@playcanvas/splat-transform 1.3.0 → 1.4.0

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/cli.mjs CHANGED
@@ -12388,6 +12388,81 @@ const readKsplat = async (source) => {
12388
12388
  return new DataTable(columns);
12389
12389
  };
12390
12390
 
12391
+ /**
12392
+ * ReadStream wrapper that adds read-ahead buffering to reduce async overhead.
12393
+ * Reads larger chunks from the inner stream and buffers excess data for
12394
+ * subsequent small reads. Useful for sources with high per-call overhead.
12395
+ *
12396
+ * @example
12397
+ * // Wrap a stream with 4MB read-ahead buffering
12398
+ * const buffered = new BufferedReadStream(rawStream, 4 * 1024 * 1024);
12399
+ * const data = await buffered.readAll();
12400
+ */
12401
+ class BufferedReadStream extends ReadStream {
12402
+ inner;
12403
+ chunkSize;
12404
+ // Buffer state
12405
+ buffer = null;
12406
+ bufferOffset = 0;
12407
+ /**
12408
+ * Create a caching wrapper around a stream.
12409
+ * @param inner - The underlying stream to read from
12410
+ * @param chunkSize - Minimum bytes to read at once from inner stream (default 64KB)
12411
+ */
12412
+ constructor(inner, chunkSize = 65536) {
12413
+ super(inner.expectedSize);
12414
+ this.inner = inner;
12415
+ this.chunkSize = chunkSize;
12416
+ }
12417
+ async pull(target) {
12418
+ // Early return for zero-length requests (e.g., EOF check from readAll)
12419
+ if (target.length === 0) {
12420
+ return 0;
12421
+ }
12422
+ let written = 0;
12423
+ // Serve from buffer first
12424
+ if (this.buffer && this.bufferOffset < this.buffer.length) {
12425
+ const available = this.buffer.length - this.bufferOffset;
12426
+ const toCopy = Math.min(available, target.length);
12427
+ target.set(this.buffer.subarray(this.bufferOffset, this.bufferOffset + toCopy));
12428
+ this.bufferOffset += toCopy;
12429
+ written += toCopy;
12430
+ this.bytesRead += toCopy;
12431
+ // Clear exhausted buffer
12432
+ if (this.bufferOffset >= this.buffer.length) {
12433
+ this.buffer = null;
12434
+ this.bufferOffset = 0;
12435
+ }
12436
+ if (written >= target.length) {
12437
+ return written;
12438
+ }
12439
+ }
12440
+ // Read a chunk from inner stream
12441
+ const remaining = target.length - written;
12442
+ const readSize = Math.max(this.chunkSize, remaining);
12443
+ const chunk = new Uint8Array(readSize);
12444
+ const n = await this.inner.pull(chunk);
12445
+ if (n === 0) {
12446
+ return written;
12447
+ }
12448
+ // Copy what we need to target
12449
+ const toCopy = Math.min(n, remaining);
12450
+ target.set(chunk.subarray(0, toCopy), written);
12451
+ written += toCopy;
12452
+ this.bytesRead += toCopy;
12453
+ // Cache the excess
12454
+ if (toCopy < n) {
12455
+ this.buffer = chunk.subarray(0, n);
12456
+ this.bufferOffset = toCopy;
12457
+ }
12458
+ return written;
12459
+ }
12460
+ close() {
12461
+ this.inner.close();
12462
+ this.buffer = null;
12463
+ }
12464
+ }
12465
+
12391
12466
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
12392
12467
  function normalizeWindowsPath(input = "") {
12393
12468
  if (!input) {
@@ -14224,7 +14299,7 @@ class CompressedChunk {
14224
14299
  }
14225
14300
  }
14226
14301
 
14227
- var version = "1.3.0";
14302
+ var version = "1.4.0";
14228
14303
 
14229
14304
  const generatedByString = `Generated by splat-transform ${version}`;
14230
14305
  const chunkProps = [
@@ -16344,7 +16419,9 @@ class NodeReadSource {
16344
16419
  // Clamp range to valid bounds
16345
16420
  const clampedStart = Math.max(0, Math.min(start, this.size));
16346
16421
  const clampedEnd = Math.max(clampedStart, Math.min(end, this.size));
16347
- return new NodeReadStream(this.fileHandle, clampedStart, clampedEnd);
16422
+ // Wrap with BufferedReadStream to reduce async overhead from file reads
16423
+ const raw = new NodeReadStream(this.fileHandle, clampedStart, clampedEnd);
16424
+ return new BufferedReadStream(raw, 4 * 1024 * 1024); // 4MB chunks
16348
16425
  }
16349
16426
  close() {
16350
16427
  this.closed = true;