You can download this code by clicking the button below.
This code is now available for download.
This function calculates the MD5 checksum of a specified file, commonly used to verify the integrity and consistency of a file.
Technology Stack : hashlib
Code Type : File checksum calculation function
Code Difficulty : Intermediate
import os
import re
import sys
import time
import random
import json
import shutil
import math
import cmath
import csv
import socket
import hashlib
import threading
import subprocess
def checksum_file(file_path):
"""
计算文件的MD5校验和。
"""
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()