Skip to content

Commit

Permalink
ZARR: check existence of metadatafiles individually. Speeds thing up …
Browse files Browse the repository at this point in the history
…for S3
  • Loading branch information
mannreis committed Jan 15, 2025
1 parent 62d6d92 commit 806c1a7
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions libnczarr/zinfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ struct ZarrObjects {
int zarr_version;
int haszmetadata;
} zarrobjects[] = {
{"zarr.json", ZARRFORMAT3, 0},
{".zgroup", ZARRFORMAT2, 0},
{".zarray", ZARRFORMAT2, 0},
{".zattrs", ZARRFORMAT2, 0},
{".zmetadata", ZARRFORMAT2, 1},
{"/zarr.json", ZARRFORMAT3, 0},
{"/.zgroup", ZARRFORMAT2, 0},
{"/.zarray", ZARRFORMAT2, 0},
{"/.zattrs", ZARRFORMAT2, 0},
{"/.zmetadata", ZARRFORMAT2, 1},
{NULL, 0, 0},
};

Expand Down Expand Up @@ -187,7 +187,6 @@ NCZ_get_open_formatter(NC_FILE_INFO_T* file, const NCZ_Formatter** formatterp)
return THROW(stat);
}

int
NCZ_infer_open_zarr_format(NC_FILE_INFO_T* file)
{
int stat = NC_NOERR;
Expand All @@ -198,8 +197,19 @@ NCZ_infer_open_zarr_format(NC_FILE_INFO_T* file)
NC_UNUSED(file);

/* Probe the map for tell-tale objects and dict keys */

if(zarrformat == 0) {
size_t seglen = 0;
struct ZarrObjects *zo = NULL;
stat = NC_ENOTZARR; // Until proven otherwise we aren't sure it's a zarr dataset
/* We search on the root path for V2 or V3 tags */
for (zo = zarrobjects; zo->name; zo++) {
if ((stat = nczmap_exists(zfile->map,zo->name)) == NC_NOERR) {
zarrformat = zo->zarr_version;
break; /* No need to look for more keys */
}
}
}
if(zarrformat == 0 || stat != NC_NOERR) {
/* We need to search subtree for a V2 or V3 tag */
switch(stat = nczmap_walk(zfile->map,"/",tagsearch, &param)) {
case NC_ENOOBJECT:
Expand Down Expand Up @@ -308,7 +318,7 @@ tagsearch(NCZMAP* map, const char* prefix, const char* key, void* param)
if(seglen == 0) return NC_NOERR;

for(zo=zarrobjects;zo->name;zo++) {
if(strcasecmp(segment,zo->name)==0) {
if(strcasecmp(segment,zo->name+1)==0) {
formats->zarrformat = zo->zarr_version;
return NC_NOERR; /* tell walker to stop */
}
Expand Down

0 comments on commit 806c1a7

Please sign in to comment.