import io


def read_until(data, char_set):
    """Reads buffered io object until an element of char_set is encountered,
    returning the read data without the terminator."""
    result = io.BytesIO()
    char_set = set(char_set)
    c = data.read(1)
    while c and c not in char_set:
        result.write(c)
        c = data.read(1)
    return result.getvalue()