(data:bytes|bytearray)
| 2 | import argparse, math, hashlib |
| 3 | |
| 4 | def _python_hash_1mb(data:bytes|bytearray): |
| 5 | chunks = [data[i:i+4096] for i in range(0, len(data), 4096)] |
| 6 | chunk_hashes = [hashlib.shake_128(chunk).digest(16) for chunk in chunks] |
| 7 | return hashlib.shake_128(b''.join(chunk_hashes)).digest(16) |
| 8 | |
| 9 | def hash_file(data: bytes|bytearray): |
| 10 | if len(data) % Tensor.CHUNK_SIZE != 0: data += bytes(Tensor.CHUNK_SIZE - len(data) % Tensor.CHUNK_SIZE) |