Skip to content

Commit

Permalink
fix(v3): Handle missing chunk_key_encoding.configuration (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Jun 20, 2024
1 parent f838137 commit 02e7855
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-shrimps-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zarrita/core": patch
---

Fix: Handle missing v3 chunk_key_encoding.configuration
4 changes: 2 additions & 2 deletions packages/core/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export type ArrayMetadata<D extends DataType = DataType> = {
};
chunk_key_encoding: {
name: "v2" | "default";
configuration: {
separator: "." | "/";
configuration?: {
separator?: "." | "/";
};
};
codecs: CodecMetadata[];
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,18 @@ function col_major_stride(shape: readonly number[]) {
return stride;
}

// https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html#chunk-key-encoding
export function create_chunk_key_encoder({
name,
configuration,
}: ArrayMetadata["chunk_key_encoding"]): (chunk_coords: number[]) => string {
if (name === "default") {
return (chunk_coords) =>
["c", ...chunk_coords].join(configuration.separator);
const separator = configuration?.separator ?? "/";
return (chunk_coords) => ["c", ...chunk_coords].join(separator);
}
if (name === "v2") {
return (chunk_coords) => chunk_coords.join(configuration.separator) || "0";
const separator = configuration?.separator ?? ".";
return (chunk_coords) => chunk_coords.join(separator) || "0";
}
throw new Error(`Unknown chunk key encoding: ${name}`);
}
Expand Down

0 comments on commit 02e7855

Please sign in to comment.