This commit is contained in:
wl-zhao
2024-10-11 17:38:11 +08:00
parent c1a131f958
commit 3e9bf28714
10 changed files with 658 additions and 149 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
import hashlib
import time
from pathlib import PurePosixPath, Path
def windows_to_linux_path(windows_path):
@@ -7,6 +7,7 @@ def windows_to_linux_path(windows_path):
def compute_sha256(file_path, chunk_size=1024 ** 2):
# Create a new sha256 hash object
start = time.time()
sha256 = hashlib.sha256()
print("start compute sha256 for", file_path)
# Open the file in binary mode
@@ -14,6 +15,6 @@ def compute_sha256(file_path, chunk_size=1024 ** 2):
# Read the file in chunks to handle large files efficiently
while chunk := file.read(chunk_size):
sha256.update(chunk)
print("finish compute sha256 for", file_path)
print("finish compute sha256 for", file_path, f"time: {time.time() - start}")
# Return the hexadecimal digest of the hash
return sha256.hexdigest()