@staticmethod
def _read_until(stream, terminator: bytes, size=None):
    """Read from the stream until the terminator byte/s are read.
        Return the bytes read including the termination bytes.
        """
    term_len = len(terminator)
    line = bytearray()
    while True:
        c = stream.read(1)
        if c:
            line += c
            if line[-term_len:] == terminator:
                break
            if size is not None and len(line) >= size:
                break
        else:
            break
    return bytes(line)
