def encode_int(value, keyspace=keyspace):
    """
    Encode a positive integer into a variable-length string.

    By default, the keyspace is ascii-compatible.

    :param value: The integer to encode.
    :type value: int
    :param keyspace: The keyspace string to use.
    :type keyspace: str
    :return: Encoded string.
    """
    if value < 0:
        raise ValueError('value must be positive')
    value = int(value)
    out = []
    while value:
        value, digit = divmod(value, len(keyspace))
        out.append(keyspace[digit])
    return ''.join(out[::-1])
