Skip to content

Commit 54dd6c1

Browse files
committed
Add numcodecs namespace and built-in shuffle/delta codecs
V2 filters and compressors are now looked up under a `numcodecs.` prefix in the codec registry, matching zarr-python's naming convention. This separates the v2-specific codec namespace from v3 codecs and makes it clear where these codecs come from. Existing codecs that serve both v2 and v3 (blosc, zstd, gzip, zlib, etc.) are registered under both names so nothing breaks. Adds `numcodecs.shuffle` and `numcodecs.delta` as built-in codecs since these are commonly requested v2 filters (#311, #315) and are trivial pure-JS implementations.
1 parent 53eff05 commit 54dd6c1

17 files changed

Lines changed: 632 additions & 20 deletions

File tree

.changeset/numcodecs-namespace.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
"zarrita": minor
3+
---
4+
5+
Add `numcodecs.` namespace for v2 codec registry and built-in shuffle/delta codecs
6+
7+
V2 filters and compressors are now registered under a `numcodecs.` prefix
8+
(e.g., `numcodecs.blosc`, `numcodecs.zlib`) matching zarr-python's convention.
9+
This separates v2-specific codecs from the v3 codec namespace.
10+
11+
Adds built-in `numcodecs.shuffle` and `numcodecs.delta` codecs for reading v2
12+
data that uses these common numcodecs filters. Both are pure JS with no WASM
13+
dependencies.
14+
15+
Custom v2 codecs can be registered under the same namespace:
16+
17+
```ts
18+
zarr.registry.set("numcodecs.my-filter", async () => ({
19+
fromConfig(config) {
20+
return {
21+
kind: "bytes_to_bytes",
22+
encode(data) { /* ... */ },
23+
decode(data) { /* ... */ },
24+
};
25+
},
26+
}));
27+
```

fixtures/v2/data.zarr/.zmetadata

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,56 @@
166166
],
167167
"zarr_format": 2
168168
},
169+
"1d.contiguous.delta.i2/.zarray": {
170+
"chunks": [
171+
4
172+
],
173+
"compressor": {
174+
"id": "zlib",
175+
"level": 1
176+
},
177+
"dtype": "<i2",
178+
"fill_value": 0,
179+
"filters": [
180+
{
181+
"astype": "<i2",
182+
"dtype": "<i2",
183+
"id": "delta"
184+
}
185+
],
186+
"order": "C",
187+
"shape": [
188+
4
189+
],
190+
"zarr_format": 2
191+
},
192+
"1d.contiguous.delta.shuffle.i2/.zarray": {
193+
"chunks": [
194+
4
195+
],
196+
"compressor": {
197+
"id": "zlib",
198+
"level": 1
199+
},
200+
"dtype": "<i2",
201+
"fill_value": 0,
202+
"filters": [
203+
{
204+
"astype": "<i2",
205+
"dtype": "<i2",
206+
"id": "delta"
207+
},
208+
{
209+
"elementsize": 2,
210+
"id": "shuffle"
211+
}
212+
],
213+
"order": "C",
214+
"shape": [
215+
4
216+
],
217+
"zarr_format": 2
218+
},
169219
"1d.contiguous.f4.be/.zarray": {
170220
"chunks": [
171221
4
@@ -277,6 +327,28 @@
277327
],
278328
"zarr_format": 2
279329
},
330+
"1d.contiguous.shuffle.i2/.zarray": {
331+
"chunks": [
332+
4
333+
],
334+
"compressor": {
335+
"id": "zlib",
336+
"level": 1
337+
},
338+
"dtype": "<i2",
339+
"fill_value": 0,
340+
"filters": [
341+
{
342+
"elementsize": 2,
343+
"id": "shuffle"
344+
}
345+
],
346+
"order": "C",
347+
"shape": [
348+
4
349+
],
350+
"zarr_format": 2
351+
},
280352
"1d.contiguous.u1/.zarray": {
281353
"chunks": [
282354
4
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"chunks": [
3+
4
4+
],
5+
"compressor": {
6+
"id": "zlib",
7+
"level": 1
8+
},
9+
"dtype": "<i2",
10+
"fill_value": 0,
11+
"filters": [
12+
{
13+
"astype": "<i2",
14+
"dtype": "<i2",
15+
"id": "delta"
16+
}
17+
],
18+
"order": "C",
19+
"shape": [
20+
4
21+
],
22+
"zarr_format": 2
23+
}
12 Bytes
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"chunks": [
3+
4
4+
],
5+
"compressor": {
6+
"id": "zlib",
7+
"level": 1
8+
},
9+
"dtype": "<i2",
10+
"fill_value": 0,
11+
"filters": [
12+
{
13+
"astype": "<i2",
14+
"dtype": "<i2",
15+
"id": "delta"
16+
},
17+
{
18+
"elementsize": 2,
19+
"id": "shuffle"
20+
}
21+
],
22+
"order": "C",
23+
"shape": [
24+
4
25+
],
26+
"zarr_format": 2
27+
}
14 Bytes
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"chunks": [
3+
4
4+
],
5+
"compressor": {
6+
"id": "zlib",
7+
"level": 1
8+
},
9+
"dtype": "<i2",
10+
"fill_value": 0,
11+
"filters": [
12+
{
13+
"elementsize": 2,
14+
"id": "shuffle"
15+
}
16+
],
17+
"order": "C",
18+
"shape": [
19+
4
20+
],
21+
"zarr_format": 2
22+
}
14 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)