from typing import IO
import hashlib


def sha256(f: IO[str]) -> str:
    """
    Calculate the sha256 message digest for a file.
    """
    pos = f.tell()
    f.seek(0)
    digest = hashlib.sha256(f.read().encode()).hexdigest()
    f.seek(pos)

    return digest