byte_sum(path) that opens a file in binary mode and returns the sum of all byte values, reading in 4096-byte chunks with the classic while + read(size) loop that stops on an empty result.byte_sum('data.bin') # file bytes: 0x01 0x023
Bytes 1 and 2 sum to 3.
Iterating a bytes object yields integers already.
while chunk := f.read(4096): is the modern idiom.