10
10
from zarr .errors import MetadataError
11
11
12
12
13
- def decode_metadata (b ):
13
+ ZARR_FORMAT = 2
14
+
15
+
16
+ def decode_array_metadata (b ):
14
17
s = text_type (b , 'ascii' )
15
18
meta = json .loads (s )
16
19
zarr_format = meta .get ('zarr_format' , None )
17
- if zarr_format != 1 :
20
+ if zarr_format != ZARR_FORMAT :
18
21
raise MetadataError ('unsupported zarr format: %s' % zarr_format )
19
22
try :
20
23
meta = dict (
@@ -33,9 +36,9 @@ def decode_metadata(b):
33
36
return meta
34
37
35
38
36
- def encode_metadata (meta ):
39
+ def encode_array_metadata (meta ):
37
40
meta = dict (
38
- zarr_format = 1 ,
41
+ zarr_format = ZARR_FORMAT ,
39
42
shape = meta ['shape' ],
40
43
chunks = meta ['chunks' ],
41
44
dtype = encode_dtype (meta ['dtype' ]),
@@ -72,3 +75,28 @@ def _decode_dtype_descr(d):
72
75
def decode_dtype (d ):
73
76
d = _decode_dtype_descr (d )
74
77
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