private function readToEndOfLine($length)
    {
        $str = $this->stream->read($length);
        if ($str === false || $str === '') {
            return $str;
        }
        while (substr($str, -1) !== "\n") {
            $chr = $this->stream->read(1);
            if ($chr === false || $chr === '') {
                break;
            }
            $str .= $chr;
        }
        return $str;
    }