import hashlib


def hash_buffer(buffer):
    """Compute the MD5 digest of a byte buffer."""
    block_size = 1024 * 1024  # 1 MiB
    m = hashlib.md5()
    while True:
        block = buffer.read(block_size)
        if not block:
            break
        m.update(block)
    return m.digest()