diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c08b8f8a..49678a44 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: hooks: - id: mypy args: [--config-file, pyproject.toml] - additional_dependencies: [numpy, pytest, crc32c, zfpy, 'zarr>=3'] + additional_dependencies: [numpy, pytest, google-crc32c, crc32c, zfpy, 'zarr>=3'] diff --git a/numcodecs/checksum32.py b/numcodecs/checksum32.py index b7d5bf0b..9ecf212e 100644 --- a/numcodecs/checksum32.py +++ b/numcodecs/checksum32.py @@ -14,7 +14,7 @@ _crc32c: ModuleType | None = None with suppress(ImportError): - import crc32c as _crc32c # type: ignore[no-redef, unused-ignore] + import google_crc32c as _crc32c # type: ignore[no-redef, unused-ignore] CHECKSUM_LOCATION = Literal['start', 'end'] @@ -179,5 +179,11 @@ class CRC32C(Checksum32): """ codec_id = 'crc32c' - checksum = _crc32c.crc32c # type: ignore[union-attr] location = 'end' + + @staticmethod + def checksum(data: Buffer, value: int = 0) -> int: + if value == 0: + return _crc32c.value(data) # type: ignore[union-attr] + else: + return _crc32c.extend(value, data) # type: ignore[union-attr] diff --git a/numcodecs/tests/test_checksum32.py b/numcodecs/tests/test_checksum32.py index 9bdc25cb..b2d91cf0 100644 --- a/numcodecs/tests/test_checksum32.py +++ b/numcodecs/tests/test_checksum32.py @@ -145,6 +145,25 @@ def test_crc32c_checksum(): assert np.frombuffer(buf, dtype="=0.3,<0.4", ] crc32c = [ - "crc32c>=2.7", + "google-crc32c>=1.5", ] [project.entry-points."zarr.codecs"]