Skip to content

Commit 0ac3581

Browse files
committed
Ensure ordering is respected
1 parent 2ef8afe commit 0ac3581

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

packages/core/src/codecs/bytes.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import type {
44
DataType,
55
TypedArrayConstructor,
66
} from "../metadata.js";
7-
import {
8-
byteswap_inplace,
9-
get_array_order,
10-
get_ctr,
11-
get_strides,
12-
} from "../util.js";
7+
import { byteswap_inplace, get_ctr, get_strides } from "../util.js";
138

149
const LITTLE_ENDIAN_OS = system_is_little_endian();
1510

packages/core/src/hierarchy.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ArrayMetadata,
66
Attributes,
77
Chunk,
8+
CodecMetadata,
89
DataType,
910
GroupMetadata,
1011
Scalar,
@@ -19,7 +20,6 @@ import {
1920
import {
2021
create_chunk_key_encoder,
2122
ensure_correct_scalar,
22-
get_array_order,
2323
get_ctr,
2424
get_strides,
2525
} from "./util.js";
@@ -28,7 +28,7 @@ export class Location<Store> {
2828
constructor(
2929
public readonly store: Store,
3030
public readonly path: AbsolutePath = "/",
31-
) {}
31+
) { }
3232

3333
resolve(path: string): Location<Store> {
3434
// reuse URL resolution logic built into the browser
@@ -63,6 +63,14 @@ export class Group<Store extends Readable> extends Location<Store> {
6363
}
6464
}
6565

66+
function get_array_order(
67+
codecs: CodecMetadata[],
68+
): "C" | "F" | globalThis.Array<number> {
69+
const maybe_transpose_codec = codecs.find((c) => c.name === "transpose");
70+
// @ts-expect-error - TODO: Should validate?
71+
return maybe_transpose_codec?.configuration?.order ?? "C";
72+
}
73+
6674
const CONTEXT_MARKER = Symbol("zarrita.context");
6775

6876
export function get_context<T>(obj: { [CONTEXT_MARKER]: T }): T {

packages/core/src/util.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,14 @@ export function create_chunk_key_encoder({
121121
throw new Error(`Unknown chunk key encoding: ${name}`);
122122
}
123123

124-
export function get_array_order(codecs: CodecMetadata[]): "C" | "F" {
125-
const maybe_transpose_codec = codecs.find((c) => c.name === "transpose");
126-
return maybe_transpose_codec?.configuration?.order === "F" ? "F" : "C";
127-
}
128-
129-
const endian_regex = /^([<|>])(.*)$/;
130-
131124
function coerce_dtype(
132125
dtype: string,
133126
): { data_type: DataType } | { data_type: DataType; endian: "little" | "big" } {
134127
if (dtype === "|O") {
135128
return { data_type: "v2:object" };
136129
}
137130

138-
let match = dtype.match(endian_regex);
131+
let match = dtype.match(/^([<|>])(.*)$/);
139132
assert(match, `Invalid dtype: ${dtype}`);
140133

141134
let [, endian, rest] = match;

0 commit comments

Comments
 (0)