Calculate the md5 checksum of a file-like object without reading its whole content in memory. >>> from io import BytesIO >>> _md5sum(BytesIO(b'file content to hash')) '784406af91dd5a54fbb9c84c2236595a'
(file: IO[bytes])
| 59 | |
| 60 | |
| 61 | def _md5sum(file: IO[bytes]) -> str: |
| 62 | """Calculate the md5 checksum of a file-like object without reading its |
| 63 | whole content in memory. |
| 64 | |
| 65 | >>> from io import BytesIO |
| 66 | >>> _md5sum(BytesIO(b'file content to hash')) |
| 67 | '784406af91dd5a54fbb9c84c2236595a' |
| 68 | """ |
| 69 | m = hashlib.md5() # noqa: S324 |
| 70 | while True: |
| 71 | d = file.read(8096) |
| 72 | if not d: |
| 73 | break |
| 74 | m.update(d) |
| 75 | return m.hexdigest() |
| 76 | |
| 77 | |
| 78 | class FileException(Exception): |
no test coverage detected