import hashlib


def sha256fromfile(abs_file_path: str) -> str:
  """
    sha256fromfile will create a sha256 digest from the file at given path.

    To preserve memory and speed up the digest,
    the file is digested with the help of a memoryview and hashlib.sha256().update.

    :raises

    Parameters
    ----------
    abs_file_path : str
        The absolute path to the file to digest

    Returns
    -------
    str
        The cast or unchanged argument

    Raises
    ------
    FileNotFoundError
        If abs_file_path is not a file
    """
  sha = hashlib.sha256()
  b = bytearray(128 * 1024)
  mv = memoryview(b)

  with open(abs_file_path, 'rb', buffering=0) as f:
    for n in iter(lambda: f.readinto(mv), 0):
      sha.update(mv[:n])
  return sha.hexdigest()