@@ -33,11 +33,13 @@ export interface Listable<Store extends Readable> {
3333
3434async function get_consolidated_metadata (
3535 store : Readable ,
36+ metadataKeyOption : string | undefined ,
3637) : Promise < ConsolidatedMetadata > {
37- let bytes = await store . get ( "/.zmetadata" ) ;
38+ const metadataKey = metadataKeyOption ?? ".zmetadata" ;
39+ let bytes = await store . get ( `/${ metadataKey } ` ) ;
3840 if ( ! bytes ) {
3941 throw new NodeNotFoundError ( "v2 consolidated metadata" , {
40- cause : new KeyError ( "/.zmetadata" ) ,
42+ cause : new KeyError ( `/ ${ metadataKey } ` ) ,
4143 } ) ;
4244 }
4345 let meta : ConsolidatedMetadata = json_decode_object ( bytes ) ;
@@ -68,13 +70,24 @@ function is_v3(meta: Metadata): meta is ArrayMetadata | GroupMetadata {
6870 return "zarr_format" in meta && meta . zarr_format === 3 ;
6971}
7072
73+ /** Options for {@linkcode withConsolidated} and {@linkcode tryWithConsolidated}. */
74+ export interface WithConsolidatedOptions {
75+ /**
76+ * Key to read consolidated metadata from.
77+ *
78+ * @default {".zmetadata"}
79+ */
80+ readonly metadataKey ?: string ;
81+ }
82+
7183/**
7284 * Open a consolidated store.
7385 *
7486 * This will open a store with Zarr v2 consolidated metadata (`.zmetadata`).
7587 * @see {@link https://zarr.readthedocs.io/en/stable/spec/v2.html#consolidated-metadata }
7688 *
7789 * @param store The store to open.
90+ * @param opts Options object.
7891 * @returns A listable store.
7992 *
8093 * @example
@@ -89,8 +102,9 @@ function is_v3(meta: Metadata): meta is ArrayMetadata | GroupMetadata {
89102 */
90103export async function withConsolidated < Store extends Readable > (
91104 store : Store ,
105+ opts : WithConsolidatedOptions = { } ,
92106) : Promise < Listable < Store > > {
93- let v2_meta = await get_consolidated_metadata ( store ) ;
107+ let v2_meta = await get_consolidated_metadata ( store , opts . metadataKey ) ;
94108 let known_meta : Record < AbsolutePath , Metadata > = { } ;
95109 for ( let [ key , value ] of Object . entries ( v2_meta . metadata ) ) {
96110 known_meta [ `/${ key } ` ] = value ;
@@ -142,12 +156,14 @@ export async function withConsolidated<Store extends Readable>(
142156 * additional network requests when accessing underlying groups and arrays.
143157 *
144158 * @param store The store to open.
159+ * @param opts Options to pass to withConsolidated.
145160 * @returns A listable store.
146161 */
147162export async function tryWithConsolidated < Store extends Readable > (
148163 store : Store ,
164+ opts : WithConsolidatedOptions = { } ,
149165) : Promise < Listable < Store > | Store > {
150- return withConsolidated ( store ) . catch ( ( error : unknown ) => {
166+ return withConsolidated ( store , opts ) . catch ( ( error : unknown ) => {
151167 rethrow_unless ( error , NodeNotFoundError ) ;
152168 return store ;
153169 } ) ;
0 commit comments