Generate hash for file or string and avoid strings starting with "ad"
       to workaround ad blocks being over aggressiv.

       The current implementation is based on sha256.

       :param str|FileIO content: The content to hash, either as string or as file-like object

def file_hash(content):
    """Generate hash for file or string and avoid strings starting with "ad"
       to workaround ad blocks being over aggressiv.

       The current implementation is based on sha256.

       :param str|FileIO content: The content to hash, either as string or as file-like object
    """
    h = hashlib.sha256()
    if isinstance(content, bytes_type):
        h.update(content)
    else:
        data = True
        while data:
            data = content.read(1024 * 1024)
            h.update(data)
    h_digest = h.digest()
    # base64url
    # | char | substitute |
    # |   +  |    -       |
    # |   /  |    _       |
    #
    result = base64.b64encode(h_digest, altchars=b'-_')
    # ensure this is a str object in 3.x
    result = result.decode('ascii')
    result = result.rstrip('=')

    if result[:2].lower() == 'ad':
        # workaround adblockers blocking everything starting with "ad"
        # by replacing the "d" with another charackter
        if result[1] == 'd':
            result = result[0] + '~' + result[2:]
        else:
            # upper case D
            result = result[0] + '.' + result[2:]

    return result