def read_till_msg(sock, msg):
    """
    Reads from socket until stream ends in msg.

    Parameter
    ---------
    sock : socket
        Socket to read from

    msg : bytearray
        bytearray

    Returns
    ------
    str

    """
    d = b''
    while True:
        data = sock.recv(4096)
        d += data
        if d.endswith(msg):
            break
    return d.decode('utf-8', 'backslashreplace')
