8
8
9
9
from zarr .abc .codec import ArrayArrayCodec , ArrayBytesCodec
10
10
from zarr .core .buffer import Buffer , NDBuffer , default_buffer_prototype
11
- from zarr .core .common import JSON , to_thread
11
+ from zarr .core .common import to_thread
12
12
from zarr .registry import get_ndbuffer_class
13
13
14
14
if TYPE_CHECKING :
15
+ import numcodecs .abc
16
+
15
17
from zarr .core .array_spec import ArraySpec
16
18
17
19
18
20
@dataclass (frozen = True )
19
21
class V2Compressor (ArrayBytesCodec ):
20
- compressor : dict [ str , JSON ] | None
22
+ compressor : numcodecs . abc . Codec | None
21
23
22
24
is_fixed_size = False
23
25
@@ -27,9 +29,8 @@ async def _decode_single(
27
29
chunk_spec : ArraySpec ,
28
30
) -> NDBuffer :
29
31
if self .compressor is not None :
30
- compressor = numcodecs .get_codec (self .compressor )
31
32
chunk_numpy_array = ensure_ndarray (
32
- await to_thread (compressor .decode , chunk_bytes .as_array_like ())
33
+ await to_thread (self . compressor .decode , chunk_bytes .as_array_like ())
33
34
)
34
35
else :
35
36
chunk_numpy_array = ensure_ndarray (chunk_bytes .as_array_like ())
@@ -47,14 +48,13 @@ async def _encode_single(
47
48
) -> Buffer | None :
48
49
chunk_numpy_array = chunk_array .as_numpy_array ()
49
50
if self .compressor is not None :
50
- compressor = numcodecs .get_codec (self .compressor )
51
51
if (
52
52
not chunk_numpy_array .flags .c_contiguous
53
53
and not chunk_numpy_array .flags .f_contiguous
54
54
):
55
55
chunk_numpy_array = chunk_numpy_array .copy (order = "A" )
56
56
encoded_chunk_bytes = ensure_bytes (
57
- await to_thread (compressor .encode , chunk_numpy_array )
57
+ await to_thread (self . compressor .encode , chunk_numpy_array )
58
58
)
59
59
else :
60
60
encoded_chunk_bytes = ensure_bytes (chunk_numpy_array )
0 commit comments