MCPcopy
hub / github.com/scrapy/scrapy / _md5sum

Function _md5sum

scrapy/pipelines/files.py:61–75  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

59
60
61def _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
78class FileException(Exception):

Callers 3

image_downloadedMethod · 0.90
stat_fileMethod · 0.85
_file_downloadedMethod · 0.85

Calls 2

readMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected