def read_var_int(file_obj):
    """Read a variable-length integer.

    Parameters
    ----------
    file_obj : file-like object
        The file to read from.

    Returns
    -------
    int
        the variable-length value read

    """
    val = 0
    shift = 0
    while True:
        next_val = ord(file_obj.read(1))
        val |= (next_val & 127) << shift
        shift += 7
        if not next_val & 128:
            break
    return val
