88
99from zarr .abc .codec import ArrayArrayCodec , ArrayBytesCodec
1010from 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
1212from zarr .registry import get_ndbuffer_class
1313
1414if TYPE_CHECKING :
15+ import numcodecs .abc
16+
1517 from zarr .core .array_spec import ArraySpec
1618
1719
1820@dataclass (frozen = True )
1921class V2Compressor (ArrayBytesCodec ):
20- compressor : dict [ str , JSON ] | None
22+ compressor : numcodecs . abc . Codec | None
2123
2224 is_fixed_size = False
2325
@@ -27,9 +29,8 @@ async def _decode_single(
2729 chunk_spec : ArraySpec ,
2830 ) -> NDBuffer :
2931 if self .compressor is not None :
30- compressor = numcodecs .get_codec (self .compressor )
3132 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 ())
3334 )
3435 else :
3536 chunk_numpy_array = ensure_ndarray (chunk_bytes .as_array_like ())
@@ -47,14 +48,13 @@ async def _encode_single(
4748 ) -> Buffer | None :
4849 chunk_numpy_array = chunk_array .as_numpy_array ()
4950 if self .compressor is not None :
50- compressor = numcodecs .get_codec (self .compressor )
5151 if (
5252 not chunk_numpy_array .flags .c_contiguous
5353 and not chunk_numpy_array .flags .f_contiguous
5454 ):
5555 chunk_numpy_array = chunk_numpy_array .copy (order = "A" )
5656 encoded_chunk_bytes = ensure_bytes (
57- await to_thread (compressor .encode , chunk_numpy_array )
57+ await to_thread (self . compressor .encode , chunk_numpy_array )
5858 )
5959 else :
6060 encoded_chunk_bytes = ensure_bytes (chunk_numpy_array )
0 commit comments