8.18.0.13
CRC32
(require crc32) | package: crc32 |
This package provides CRC32 (IEEE 802.3 standard) checksum computation functions.
CRC32 is commonly used for error detection in network transmissions and file integrity checks.
1 API Reference
procedure
bs : bytes?
Computes the CRC32 checksum of the given byte string.
Examples:
> (require crc32) > (crc32-bytes #"abc") 891568578
> (number->string (crc32-bytes #"abc") 16) "352441c2"
procedure
str : string?
Computes the CRC32 checksum of the UTF-8 encoding of the given string.
Examples:
> (require crc32) > (crc32-string/utf8 "hello") 907060870
> (number->string (crc32-string/utf8 "hello") 16) "3610a686"
procedure
str : string?
Computes the CRC32 checksum of the Latin-1 encoding of the given string.
procedure
str : string?
Computes the CRC32 checksum of the locale encoding of the given string.
procedure
in : input-port? = (current-input-port)
Computes the CRC32 checksum of all bytes read from the input port.
Examples:
> (require crc32) > (crc32-input-port (open-input-bytes #"test data")) 3540561586
2 Low-level API
For incremental computation or when you need more control over the process:
The initial value for CRC32 computation (4294967295).
procedure
(crc32-update acc byte) → exact-nonnegative-integer?
acc : exact-nonnegative-integer? byte : exact-nonnegative-integer?
Updates the CRC32 accumulator with a single byte.
procedure
acc : exact-nonnegative-integer?
Finalizes the CRC32 computation by applying the final XOR.
3 Examples
Examples:
> (require crc32) > (crc32-bytes #"hello world") 222957957
> (define acc crc32-initial-value) > (set! acc (crc32-update acc 104)) > (set! acc (crc32-update acc 101)) > (set! acc (crc32-update acc 108)) > (set! acc (crc32-update acc 108)) > (set! acc (crc32-update acc 111)) > (crc32-finalize acc) 907060870
> (crc32-bytes #"hello") 907060870