all Python 3zlibfunction
zlib.crc32()
checksums
Computes the CRC-32 checksum of bytes; you can compute it in pieces by passing the previous value.
Syntax
zlib.crc32(data[, value])
It guards against accidental corruption, not attacks: crafting data with a chosen CRC is easy, so use hashlib for passwords and signatures. Since Python 3 the result is always unsigned (0…2**32-1); in Python 2 it could be negative, so old recipes with & 0xffffffff are no longer needed. To checksum a file in pieces, pass the running value as the second argument; ZIP and gzip use this same CRC-32.
Examples
import zlib
print(zlib.crc32(b'hello')) # → 907060870
running = zlib.crc32(b'hel')
running = zlib.crc32(b'lo', running)
print(running == zlib.crc32(b'hello')) # → True
print(zlib.crc32(b'')) # → 0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy