from typing import Union
import io


def _hash(fn, buffer: Union[io.StringIO, io.BytesIO]):
    """Partial function for generating checksum of binary content."""

    buffer.seek(0)
    hashsum = fn()
    for chunk in iter(lambda: buffer.read(4096), b''):
        hashsum.update(chunk)
    return hashsum.hexdigest()