Skip to content

Commit

Permalink
added are_files_equal to file_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Apr 25, 2024
1 parent 4d9a4a8 commit d932bba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Change Log
- Added extract_file_from_zip to zip_utils.
- Added http_utils with download function.
- Added get_app_specific_directory, get_os_name, and get_cpu_architecture_name to misc_utils.
- Added normalize_file_path to file_utils.
- Added normalize_file_path and are_files_equal to file_utils.
- Added create_temporary_file_name and remove_temporary_file tmpfile_utils.
- Minor fix to misc_utils.create_dict (do not create property only if its value is None).

Expand Down
20 changes: 20 additions & 0 deletions dcicutils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,23 @@ def normalize_file_path(path: str, home_directory: bool = True) -> str:
if path.startswith(home_directory) and path != home_directory:
path = "~/" + pathlib.Path(path).relative_to(home_directory).as_posix()
return path


def are_files_equal(filea: str, fileb: str) -> bool:
"""
Returns True iff the contents of the two given files are exactly the same.
"""
try:
with open(filea, "rb") as fa:
with open(fileb, "rb") as fb:
chunk_size = 4096
while True:
chunka = fa.read(chunk_size)
chunkb = fb.read(chunk_size)
if chunka != chunkb:
return False
if not chunka:
break
return True
except Exception:
return False
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.4.1b7" # TODO: To become 8.8.5
version = "8.8.4.1b8" # TODO: To become 8.8.5
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit d932bba

Please sign in to comment.