MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / checksum

Function checksum

src/commoncode/hash.py:217–229  ·  view source on GitHub ↗

Return a checksum from the content of the file at ``location`` using the ``name`` checksum algorithm. The checksum is a string as a hexdigest or is base64-encoded is ``base64`` is True. Return None if ``location`` is not a file or an empty file.

(location, name, base64=False)

Source from the content-addressed store, hash-verified

215
216
217def checksum(location, name, base64=False):
218 """
219 Return a checksum from the content of the file at ``location`` using the ``name`` checksum
220 algorithm. The checksum is a string as a hexdigest or is base64-encoded is ``base64`` is True.
221
222 Return None if ``location`` is not a file or an empty file.
223 """
224 if not filetype.is_file(location):
225 return
226
227 total_length = get_file_size(location)
228 chunks = binary_chunks(location)
229 return checksum_from_chunks(chunks=chunks, total_length=total_length, name=name, base64=base64)
230
231
232def checksum_from_chunks(chunks, name, total_length=0, base64=False):

Callers 8

test_checksum_sha1Method · 0.90
test_checksum_md5Method · 0.90
md5Function · 0.85
sha1Function · 0.85
b64sha1Function · 0.85
sha256Function · 0.85
sha512Function · 0.85
sha1_gitFunction · 0.85

Calls 3

get_file_sizeFunction · 0.85
binary_chunksFunction · 0.85
checksum_from_chunksFunction · 0.85

Tested by 2

test_checksum_sha1Method · 0.72
test_checksum_md5Method · 0.72