Calculate sha1 of path. Read file in chunks.
(path)
| 215 | |
| 216 | |
| 217 | def sha1_file(path): |
| 218 | """Calculate sha1 of path. Read file in chunks.""" |
| 219 | assert os.path.isfile(path) |
| 220 | chunk_size = 1024 * 1024 # 1M |
| 221 | sha1_checksum = hashlib.sha1() |
| 222 | with open(path, "rb") as f: |
| 223 | byte = f.read(chunk_size) |
| 224 | while byte: |
| 225 | sha1_checksum.update(byte) |
| 226 | byte = f.read(chunk_size) |
| 227 | return sha1_checksum.hexdigest() |
| 228 | |
| 229 | |
| 230 | if __name__ == "__main__": |