icechunk-js 0.5.0 → 0.5.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/index.cjs CHANGED
@@ -2441,7 +2441,7 @@ function parseManifest(data) {
2441
2441
  for (let i = 0; i < arraysLength; i++) {
2442
2442
  const fbsArray = fbsManifest.arrays(i);
2443
2443
  if (fbsArray) {
2444
- arrays.push(parseArrayManifest(fbsArray, decodeLocation));
2444
+ arrays.push(makeArrayManifest(fbsArray, decodeLocation));
2445
2445
  }
2446
2446
  }
2447
2447
  return { id, arrays };
@@ -2469,22 +2469,32 @@ function makeLocationDecoder(fbsManifest) {
2469
2469
  return textDecoder.decode(decompressed);
2470
2470
  };
2471
2471
  }
2472
- function parseArrayManifest(fbsArray, decodeLocation) {
2472
+ function makeArrayManifest(fbsArray, decodeLocation) {
2473
2473
  const nodeIdObj = fbsArray.nodeId();
2474
2474
  if (!nodeIdObj)
2475
2475
  throw new Error("ArrayManifest missing required node_id field");
2476
2476
  const nodeId = asObjectId8(
2477
2477
  nodeIdObj.bb.bytes().slice(nodeIdObj.bb_pos, nodeIdObj.bb_pos + 8)
2478
2478
  );
2479
- const refsLength = fbsArray.refsLength();
2480
- const refs = [];
2481
- for (let i = 0; i < refsLength; i++) {
2482
- const fbsRef = fbsArray.refs(i);
2483
- if (fbsRef) {
2484
- refs.push(parseChunkRef(fbsRef, decodeLocation));
2479
+ const numRefs = fbsArray.refsLength();
2480
+ const probe = new ChunkRef();
2481
+ return {
2482
+ nodeId,
2483
+ numRefs,
2484
+ refIndex(i) {
2485
+ const fbsRef = fbsArray.refs(i, probe);
2486
+ if (!fbsRef) throw new Error(`Manifest ref ${i} out of range`);
2487
+ const indexLength = fbsRef.indexLength();
2488
+ const index = new Array(indexLength);
2489
+ for (let d = 0; d < indexLength; d++) index[d] = fbsRef.index(d);
2490
+ return index;
2491
+ },
2492
+ refAt(i) {
2493
+ const fbsRef = fbsArray.refs(i);
2494
+ if (!fbsRef) throw new Error(`Manifest ref ${i} out of range`);
2495
+ return parseChunkRef(fbsRef, decodeLocation);
2485
2496
  }
2486
- }
2487
- return { nodeId, refs };
2497
+ };
2488
2498
  }
2489
2499
  function parseChunkRef(fbsRef, decodeLocation) {
2490
2500
  const indexLength = fbsRef.indexLength();
@@ -2535,7 +2545,7 @@ function parseChunkRef(fbsRef, decodeLocation) {
2535
2545
  function findChunkRef(manifest, nodeId, coords) {
2536
2546
  const arrayManifest = binarySearchArrayManifest(manifest.arrays, nodeId);
2537
2547
  if (!arrayManifest) return null;
2538
- return binarySearchChunkRef(arrayManifest.refs, coords);
2548
+ return binarySearchChunkRef(arrayManifest, coords);
2539
2549
  }
2540
2550
  function binarySearchArrayManifest(arrays, nodeId) {
2541
2551
  let low = 0;
@@ -2567,14 +2577,14 @@ function compareCoords(a, b) {
2567
2577
  }
2568
2578
  return a.length - b.length;
2569
2579
  }
2570
- function binarySearchChunkRef(refs, coords) {
2580
+ function binarySearchChunkRef(array, coords) {
2571
2581
  let low = 0;
2572
- let high = refs.length - 1;
2582
+ let high = array.numRefs - 1;
2573
2583
  while (low <= high) {
2574
2584
  const mid = Math.floor((low + high) / 2);
2575
- const cmp = compareCoords(refs[mid].index, coords);
2585
+ const cmp = compareCoords(array.refIndex(mid), coords);
2576
2586
  if (cmp === 0) {
2577
- return refs[mid];
2587
+ return array.refAt(mid);
2578
2588
  } else if (cmp < 0) {
2579
2589
  low = mid + 1;
2580
2590
  } else {