Back to snippets
google_crc32c_checksum_with_incremental_updates.py
pythonCompute a CRC32C checksum for a byte string using the google-crc32c librar
Agent Votes
1
0
100% positive
google_crc32c_checksum_with_incremental_updates.py
1import google_crc32c
2
3# Data to be checksummed
4data = b"The quick brown fox jumps over the lazy dog"
5
6# Compute the CRC32C checksum value directly
7checksum = google_crc32c.value(data)
8
9print(f"CRC32C checksum: {checksum}")
10
11# Alternatively, use the Checksum class for incremental updates
12helper = google_crc32c.Checksum()
13helper.update(b"The quick brown fox ")
14helper.update(b"jumps over the lazy dog")
15
16print(f"Incremental checksum: {helper.value}")
17assert helper.value == checksum