import hashlib


def checksum_file(filename, *, algorithm="sha256", block_size=1048576):
    """
    Return checksums (hash) of a file.

    Arguments:
        filename           (str): file to check hash

    Keyword arguments (opt):
        algorithm          (str): algorithm used to calculate hash.
                                  default: sha256
        block_size         (int): chunk size to read the file (bytes)

    return:
        hex-encoded string

    Example:
    >>> checksum_file("my_file") # doctest: +SKIP
    '179b8c9510b2f068b94286c86610c6fe633ca44b5e541837ae9461bbdace7191'
    >>> checksum_file("my_file", algorithm="md5") # doctest: +SKIP
    'bdc28791ea81bafa7601e98f68b692e5'
    """
    try:
        file_hash = getattr(hashlib, algorithm)()
    except AttributeError:
        raise TypeError("hash algorithm not supported")

    if not isinstance(block_size, int):
        raise TypeError("block_size should be int")

    with open(filename, "rb") as fd:
        block = fd.read(block_size)
        while block:
            file_hash.update(block)
            block = fd.read(block_size)

    return file_hash.hexdigest()