Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler file chunking #1188

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/_utils/_common_utils_for_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def check_hash_fn(filepath, expected_hash, hash_type="md5"):
raise ValueError("Invalid hash_type requested, should be one of {}".format(["sha256", "md5"]))

with open(filepath, "rb") as f:
chunk = f.read(1024 ** 2)
while chunk:
while chunk := f.read(1024 ** 2):
hash_fn.update(chunk)
chunk = f.read(1024 ** 2)

return hash_fn.hexdigest() == expected_hash
4 changes: 1 addition & 3 deletions torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ def _hash_check(filepath, hash_dict, hash_type):
# TODO(634): Line above will require all readers (Win) to obtain proper locks,
# I'm putting it on hold as we need to modify PyTorch core codebase heavily.
with open(filepath, "rb") as f:
chunk = f.read(1024 ** 2)
while chunk:
while chunk := f.read(1024 ** 2):
hash_func.update(chunk)
chunk = f.read(1024 ** 2)

return hash_func.hexdigest() == hash_dict[filepath]

Expand Down
Loading