Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
19 lines
925 B
Python
19 lines
925 B
Python
#!/usr/bin/env python3
|
|
"""Reference for bulk_read_bench --digest: sha256 over the sha256 digests of consecutive CHUNK_MIB blocks (one plain sequential pass).
|
|
Offline check only. usage: bulk_read_digest.py PATH START_MIB LEN_MIB CHUNK_MIB (LEN_MIB 0: to the end)"""
|
|
import hashlib, os, sys
|
|
path, start, chunk = sys.argv[1], int(sys.argv[2]) << 20, int(sys.argv[4]) << 20
|
|
length = (os.path.getsize(path) - start) if int(sys.argv[3]) == 0 else int(sys.argv[3]) << 20 # LEN_MIB 0: to the end of the file, as the bench does
|
|
outer = hashlib.sha256()
|
|
fd = os.open(path, os.O_RDONLY)
|
|
off = start
|
|
while off < start + length:
|
|
n = min(chunk, start + length - off)
|
|
data = os.pread(fd, n, off)
|
|
while len(data) < n:
|
|
data += os.pread(fd, n - len(data), off + len(data))
|
|
outer.update(hashlib.sha256(data).digest())
|
|
off += n
|
|
os.posix_fadvise(fd, start, length, os.POSIX_FADV_DONTNEED)
|
|
print(outer.hexdigest())
|