Skip to content

Commit bb22366

Browse files
committed
chore(crc32c): replace crc32c with google-crc32c dependency
1 parent 6811c94 commit bb22366

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ repos:
3131
# Package dependencies
3232
- packaging
3333
- donfig
34-
- numcodecs[crc32c]
34+
- numcodecs
35+
- google-crc32c>=1.5
3536
- numpy==2.1 # until https://github.com/numpy/numpy/issues/28034 is resolved
3637
- typing_extensions
3738
- universal-pathlib

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ requires-python = ">=3.11"
3434
dependencies = [
3535
'packaging>=22.0',
3636
'numpy>=1.26',
37-
'numcodecs[crc32c]>=0.14',
37+
'numcodecs>=0.14',
38+
'google-crc32c>=1.5',
3839
'typing_extensions>=4.9',
3940
'donfig>=0.8',
4041
]

src/zarr/codecs/crc32c_.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from dataclasses import dataclass
44
from typing import TYPE_CHECKING, cast
55

6+
import google_crc32c
67
import numpy as np
78
import typing_extensions
8-
from crc32c import crc32c
99

1010
from zarr.abc.codec import BytesBytesCodec
1111
from zarr.core.common import JSON, parse_named_configuration
@@ -42,7 +42,7 @@ async def _decode_single(
4242

4343
# Need to do a manual cast until https://github.com/numpy/numpy/issues/26783 is resolved
4444
computed_checksum = np.uint32(
45-
crc32c(cast("typing_extensions.Buffer", inner_bytes))
45+
google_crc32c.value(cast("typing_extensions.Buffer", inner_bytes))
4646
).tobytes()
4747
stored_checksum = bytes(crc32_bytes)
4848
if computed_checksum != stored_checksum:
@@ -58,7 +58,9 @@ async def _encode_single(
5858
) -> Buffer | None:
5959
data = chunk_bytes.as_numpy_array()
6060
# Calculate the checksum and "cast" it to a numpy array
61-
checksum = np.array([crc32c(cast("typing_extensions.Buffer", data))], dtype=np.uint32)
61+
checksum = np.array(
62+
[google_crc32c.value(cast("typing_extensions.Buffer", data))], dtype=np.uint32
63+
)
6264
# Append the checksum (as bytes) to the data
6365
return chunk_spec.prototype.buffer.from_array_like(np.append(data, checksum.view("B")))
6466

0 commit comments

Comments
 (0)