Skip to content

Commit

Permalink
Poor's man HTTP implemementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mannreis committed Dec 4, 2024
1 parent 48b283b commit 348ca1a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions libnczarr/zarr.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ applycontrols(NCZ_FILE_INFO_T* zinfo)
}
/* Process the modelist first */
zinfo->controls.mapimpl = NCZM_DEFAULT;
if( strncmp("http://",zinfo->common.file->hdr.name,7) == 0 ||
strncmp("https://",zinfo->common.file->hdr.name,8) == 0 ){
zinfo->controls.mapimpl = NCZM_HTTP;
}
zinfo->controls.flags |= FLAG_XARRAYDIMS; /* Always support XArray convention where possible */
for(i=0;i<nclistlength(modelist);i++) {
const char* p = nclistget(modelist,i);
Expand Down
6 changes: 5 additions & 1 deletion libnczarr/zmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ nczmap_open(NCZM_IMPL impl, const char *path, int mode, size64_t flags, void* pa
#endif
#ifdef NETCDF_ENABLE_S3
case NCZM_S3:
stat = zmap_s3sdk.open(path, mode, flags, parameters, &map);
stat = zmap_s3sdk.open(path, mode, flags, parameters!=NULL, &map);
if(stat) goto done;
break;
case NCZM_HTTP:
stat = zmap_s3sdk.open(path, mode, flags, NULL, &map);
if(stat) goto done;
break;
#endif
Expand Down
1 change: 1 addition & 0 deletions libnczarr/zmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ NCZM_UNDEF=0, /* In-memory implementation */
NCZM_FILE=1, /* File system directory-based implementation */
NCZM_ZIP=2, /* Zip-file based implementation */
NCZM_S3=3, /* Amazon S3 implementation */
NCZM_HTTP=4, /* Low effort HTTP implementation based on S3's */
} NCZM_IMPL;

/* Define the default map implementation */
Expand Down
22 changes: 13 additions & 9 deletions libnczarr/zmap_s3sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ zs3open(const char *path, int mode, size64_t flags, void* parameters, NCZMAP** m
size_t nkeys = 0;

NC_UNUSED(flags);
NC_UNUSED(parameters);

ZTRACE(6,"path=%s mode=%d flags=%llu",path,mode,flags);

Expand Down Expand Up @@ -223,14 +222,17 @@ zs3open(const char *path, int mode, size64_t flags, void* parameters, NCZMAP** m
z3map->s3client = NC_s3sdkcreateclient(&z3map->s3);

/* Search the root for content */
// content = nclistnew();
// if((stat = NC_s3sdkgetkeys(z3map->s3client,z3map->s3.bucket,z3map->s3.rootkey,&nkeys,NULL,&z3map->errmsg)))
// goto done;
// if(nkeys == 0) {
// /* dataset does not actually exist; we choose to return ENOOBJECT instead of EEMPTY */
// stat = NC_ENOOBJECT;
// goto done;
// }
if (parameters) {
content = nclistnew();
if((stat = NC_s3sdkgetkeys(z3map->s3client,z3map->s3.bucket,z3map->s3.rootkey,&nkeys,NULL,&z3map->errmsg)))
goto done;
if(nkeys == 0) {
/* dataset does not actually exist; we choose to return ENOOBJECT instead of EEMPTY */
stat = NC_ENOOBJECT;
goto done;
}
}

if(mapp) *mapp = (NCZMAP*)z3map;

done:
Expand Down Expand Up @@ -588,3 +590,5 @@ nczs3sdkapi = {
zs3write,
zs3search,
};


0 comments on commit 348ca1a

Please sign in to comment.