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

Function checksum_from_chunks

src/commoncode/hash.py:232–243  ·  view source on GitHub ↗

Return a checksum from the content of the iterator of byte strings ``chunks`` with a ``total_length`` combined length using the ``name`` checksum algorithm. The returned checksum is a string as a hexdigest or is base64-encoded is ``base64`` is True.

(chunks, name, total_length=0, base64=False)

Source from the content-addressed store, hash-verified

230
231
232def checksum_from_chunks(chunks, name, total_length=0, base64=False):
233 """
234 Return a checksum from the content of the iterator of byte strings ``chunks`` with a
235 ``total_length`` combined length using the ``name`` checksum algorithm. The returned checksum is
236 a string as a hexdigest or is base64-encoded is ``base64`` is True.
237 """
238 hasher = get_hasher_instance_by_name(name=name, total_length=total_length)
239 for chunk in chunks:
240 hasher.update(chunk)
241 if base64:
242 return hasher.b64digest()
243 return hasher.hexdigest()
244
245
246def binary_chunks(location, size=FILE_CHUNK_SIZE):

Calls 4

b64digestMethod · 0.80
hexdigestMethod · 0.80
updateMethod · 0.45