import hashlib


def compress(string: str, max_length: int = 64) -> str:
    """
    Compress a string to a string of restricted length.

    The function can be useful, because some filesystems and/or
    disk encryption tools impose restriction on maximum length of
    a filename.

    :param string:
        string to be compressed
    :param max_length:
        maximum length of output, default is 64
    :return:
        compressed string which is a truncated hash of input string
    """
    hashed_string = hashlib.sha256(string.encode('utf-8')).hexdigest()
    result = hashed_string[:max_length]
    return result