Skip to content

Commit 08f86e9

Browse files
committed
extract_utils: make hashing chunked
Change-Id: I26c03557a80b00d0da2f2ed0f217d7c0adf4f9ec
1 parent f9088e2 commit 08f86e9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

extract_utils/utils.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from subprocess import PIPE, Popen, run
1616
from typing import Generator, Iterable, List, Optional, Tuple
1717

18+
CHUNK_SIZE = 1024 * 1024
19+
1820

1921
def import_module(module_name, module_path):
2022
spec = importlib.util.spec_from_file_location(module_name, module_path)
@@ -52,10 +54,15 @@ def remove_dir_contents(dir_path: str):
5254

5355

5456
def file_path_hash(file_path: str, hash_fn):
57+
file_hash = hash_fn()
5558
with open(file_path, 'rb') as f:
56-
data = f.read()
57-
file_hash = hash_fn(data)
58-
return file_hash.hexdigest()
59+
while True:
60+
data = f.read(CHUNK_SIZE)
61+
if not data:
62+
break
63+
64+
file_hash.update(data)
65+
return file_hash.hexdigest()
5966

6067

6168
def file_path_sha1(file_path: str):

0 commit comments

Comments
 (0)