Spaces:
Paused
Paused
Download src/storage/crc.py from ThomasHeisig/Brain-5D-Space: direct link, hf CLI and curl.
- Browser
- Download file 654 Bytes
-
https://huggingface.co/spaces/ThomasHeisig/Brain-5D-Space/resolve/main/src/storage/crc.py
- Command line
-
hf download hf://spaces/ThomasHeisig/Brain-5D-Space/src/storage/crc.py
-
curl -L -o crc.py https://huggingface.co/spaces/ThomasHeisig/Brain-5D-Space/resolve/main/src/storage/crc.py
654 Bytes
| """CRC32 helpers used by the Brain-5D append-only journal.""" | |
| from __future__ import annotations | |
| import zlib | |
| UINT32_MASK = 0xFFFF_FFFF | |
| def compute_crc32(data: bytes, initial: int = 0) -> int: | |
| """Return the unsigned CRC32 of *data* using the standard library.""" | |
| if not 0 <= initial <= UINT32_MASK: | |
| raise ValueError("initial CRC must fit uint32") | |
| return zlib.crc32(data, initial) & UINT32_MASK | |
| def verify_crc32(data: bytes, expected: int) -> bool: | |
| """Return whether *data* matches the expected unsigned CRC32 value.""" | |
| if not 0 <= expected <= UINT32_MASK: | |
| return False | |
| return compute_crc32(data) == expected | |