Python: calculate crc32 checksum for a file








def crc32(path):
    from zlib import crc32
    with open(path, 'r') as f:
        crc = crc32('')
        while True:
            data = f.read(BUFFER_SIZE)
            if not data:
                break
            crc = crc32(data, crc)
    return crc

def main():
    csum = crc32('/tmp/123.dat')
    print(str(hex(csum)))

if __name__ == '__main__'
    main()



No comments:

Post a Comment