Skip to content

Commit 27049d5

Browse files
committed
add support for group metadata
1 parent eb9e59b commit 27049d5

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

zarr/meta.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
from zarr.errors import MetadataError
1111

1212

13-
def decode_metadata(b):
13+
ZARR_FORMAT = 2
14+
15+
16+
def decode_array_metadata(b):
1417
s = text_type(b, 'ascii')
1518
meta = json.loads(s)
1619
zarr_format = meta.get('zarr_format', None)
17-
if zarr_format != 1:
20+
if zarr_format != ZARR_FORMAT:
1821
raise MetadataError('unsupported zarr format: %s' % zarr_format)
1922
try:
2023
meta = dict(
@@ -33,9 +36,9 @@ def decode_metadata(b):
3336
return meta
3437

3538

36-
def encode_metadata(meta):
39+
def encode_array_metadata(meta):
3740
meta = dict(
38-
zarr_format=1,
41+
zarr_format=ZARR_FORMAT,
3942
shape=meta['shape'],
4043
chunks=meta['chunks'],
4144
dtype=encode_dtype(meta['dtype']),
@@ -72,3 +75,28 @@ def _decode_dtype_descr(d):
7275
def decode_dtype(d):
7376
d = _decode_dtype_descr(d)
7477
return np.dtype(d)
78+
79+
80+
def decode_group_metadata(b):
81+
s = text_type(b, 'ascii')
82+
meta = json.loads(s)
83+
zarr_format = meta.get('zarr_format', None)
84+
if zarr_format != ZARR_FORMAT:
85+
raise MetadataError('unsupported zarr format: %s' % zarr_format)
86+
try:
87+
meta = dict(
88+
zarr_format=meta['zarr_format'],
89+
)
90+
except Exception as e:
91+
raise MetadataError('error decoding metadata: %s' % e)
92+
else:
93+
return meta
94+
95+
96+
def encode_group_metadata(meta=None):
97+
meta = dict(
98+
zarr_format=ZARR_FORMAT,
99+
)
100+
s = json.dumps(meta, indent=4, sort_keys=True, ensure_ascii=True)
101+
b = s.encode('ascii')
102+
return b

0 commit comments

Comments
 (0)