Skip to content

Instantly share code, notes, and snippets.

@xtman
Created January 29, 2022 09:03
Show Gist options
  • Save xtman/1c75a91350c7a6d614aed00261afa204 to your computer and use it in GitHub Desktop.
Save xtman/1c75a91350c7a6d614aed00261afa204 to your computer and use it in GitHub Desktop.
Generate CRC32 checksum for a file
import zlib
import sys
BUFFER_SIZE=8192
def get_crc32(path):
with open(path, 'rb') as f:
crc = 0
while True:
data = f.read(BUFFER_SIZE)
if not data:
break
crc = zlib.crc32(data, crc)
return crc
def main():
for f in sys.argv[1:]:
crc32 = get_crc32(f)
crc32hex = hex(crc32)[2:]
print(f'{f}: {crc32hex}')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment