manzt / zarrita.js

A JavaScript toolkit for working with chunked, compressed, n-dimensional arrays
https://zarrita.dev
MIT License
44 stars 5 forks source link

feat: consolidate v2 and v3 implementations into `@zarrita/core` #65

Closed manzt closed 1 year ago

manzt commented 1 year ago

WIP, introducing a unified API for reading v2 & v3, and writing v3.

Open v3

import * as zarr from "@zarrita/core";
import { FileSystemStore } from "@zarrita/storage";

let store = zarr.root(new FileSystemStore("teststore"));
let node = await zarr.open(store.resolve("foo")); // type Array | Group

let arr = await zarr.open(store.resolve("foo"), { kind: "array" }); // type Array
let grp = await zarr.open(store.resolve("baz"), { kind: "group" }) // type Group

Open v2

import * as zarr from "@zarrita/core";
import { FileSystemStore } from "@zarrita/storage";

let store = zarr.root(new FileSystemStore("teststore"), { version: "2" });
let node = await zarr.open(store.resolve("foo")); // type Array | Group

let arr = await zarr.open(store.resolve("foo"), { kind: "array" }); // type Array
let grp = await zarr.open(store.resolve("baz"), { kind: "group" }) // type Group

Write v3

import * as zarr from "@zarrita/core";
import { FileSystemStore } from "@zarrita/storage";

let store = zarr.root(new FileSystemStore("teststore"));
let arr = await zarr.create(store.resolve("foo"), {
  shape: [100, 100],
  data_type: "int32",
  chunk_shape: [10, 10],
});
let grp = await zarr.create(store.resolve("baz"), { attributes: { answer: 42 } });

Write v2 (throws)

import * as zarr from "@zarrita/core";
import { FileSystemStore } from "@zarrita/storage";

let store = zarr.root(new FileSystemStore("teststore"), { version: "2" });
let arr = await zarr.create(store.resolve("foo"), {
  shape: [100, 100],
  data_type: "int32",
  chunk_shape: [10, 10],
}); // throws!