class HTTPFileChunkStore {
constructor(url, chunk_offsets) {
this.url = url;
this.chunk_offsets = chunk_offsets;
}
async getItem(key) {
const res = this.chunk_offsets[key];
if (!res) {
throw new zarr.KeyError();
}
if (!("offset" in res)) {
const meta = JSON.stringify(res);
const enc = new TextEncoder().encode(meta);
return enc.buffer;
}
const { offset, size } = res;
const chunk = await fetch(this.url, {
headers: { Range: `bytes=${offset}-${offset + size - 1}` }
}).then(res => res.arrayBuffer());
return chunk;
}
async containsItem(key) {
const res = this.chunk_offsets[key];
if (!res) return false;
return true;
}
}