Created
January 29, 2022 09:03
-
-
Save xtman/1c75a91350c7a6d614aed00261afa204 to your computer and use it in GitHub Desktop.
Generate CRC32 checksum for a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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