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)
| 230 | |
| 231 | |
| 232 | def 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 | |
| 246 | def binary_chunks(location, size=FILE_CHUNK_SIZE): |