MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / filecmp

Function filecmp

tensorflow/python/lib/io/file_io.py:748–774  ·  view source on GitHub ↗

Compare two files, returning True if they are the same, False otherwise. We check size first and return False quickly if the files are different sizes. If they are the same size, we continue to generating a crc for the whole file. You might wonder: why not use Python's filecmp.cmp() instead?

(filename_a, filename_b)

Source from the content-addressed store, hash-verified

746
747
748def filecmp(filename_a, filename_b):
749 """Compare two files, returning True if they are the same, False otherwise.
750
751 We check size first and return False quickly if the files are different sizes.
752 If they are the same size, we continue to generating a crc for the whole file.
753
754 You might wonder: why not use Python's filecmp.cmp() instead? The answer is
755 that the builtin library is not robust to the many different filesystems
756 TensorFlow runs on, and so we here perform a similar comparison with
757 the more robust FileIO.
758
759 Args:
760 filename_a: string path to the first file.
761 filename_b: string path to the second file.
762
763 Returns:
764 True if the files are the same, False otherwise.
765 """
766 size_a = FileIO(filename_a, "rb").size()
767 size_b = FileIO(filename_b, "rb").size()
768 if size_a != size_b:
769 return False
770
771 # Size is the same. Do a full check.
772 crc_a = file_crc32(filename_a)
773 crc_b = file_crc32(filename_b)
774 return crc_a == crc_b
775
776
777def file_crc32(filename, block_size=_DEFAULT_BLOCK_SIZE):

Callers

nothing calls this directly

Calls 3

FileIOClass · 0.85
file_crc32Function · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected