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

Function file_crc32

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

Get the crc32 of the passed file. The crc32 of a file can be used for error checking; two files with the same crc32 are considered equivalent. Note that the entire file must be read to produce the crc32. Args: filename: string, path to a file block_size: Integer, process the files

(filename, block_size=_DEFAULT_BLOCK_SIZE)

Source from the content-addressed store, hash-verified

775
776
777def file_crc32(filename, block_size=_DEFAULT_BLOCK_SIZE):
778 """Get the crc32 of the passed file.
779
780 The crc32 of a file can be used for error checking; two files with the same
781 crc32 are considered equivalent. Note that the entire file must be read
782 to produce the crc32.
783
784 Args:
785 filename: string, path to a file
786 block_size: Integer, process the files by reading blocks of `block_size`
787 bytes. Use -1 to read the file as once.
788
789 Returns:
790 hexadecimal as string, the crc32 of the passed file.
791 """
792 crc = 0
793 with FileIO(filename, mode="rb") as f:
794 chunk = f.read(n=block_size)
795 while chunk:
796 crc = binascii.crc32(chunk, crc)
797 chunk = f.read(n=block_size)
798 return hex(crc & 0xFFFFFFFF)

Callers 1

filecmpFunction · 0.85

Calls 2

FileIOClass · 0.85
readMethod · 0.45

Tested by

no test coverage detected