Returns first n lines of stream.

@param  int $len
@return string|int the resulting stream, or -1
if the end of the resulting stream has been reached
972033
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->initialize();
            $this->setInitialized(true);
        }

        // note, if buffer contains fewer lines than
        // $this->_lines this code will not work.

        if ($this->linesRead < $this->lines) {
            $buffer = $this->in->read($len);

            if ($buffer === -1) {
                return -1;
            }

            // now grab first X lines from buffer

            $lines = explode("\n", $buffer);

            $linesCount = count($lines);

            // must account for possibility that the num lines requested could
            // involve more than one buffer read.
            $len = ($linesCount > $this->lines ? $this->lines - $this->linesRead : $linesCount);
            $filtered_buffer = implode("\n", array_slice($lines, $this->skip, $len));
            $this->linesRead += $len;

            return $filtered_buffer;
        }

        return -1; // EOF, since the file is "finished" as far as subsequent filters are concerned.
    }
1039219
public function seekAndRead($length)
    {
        $this->stream->seek($this->offset + $this->position);
        if ($this->limit !== -1) {
            $length = min($length, $this->limit - $this->position);
            if ($length <= 0) {
                return '';
            }
        }
        return $this->stream->read($length);
    }
92836
private function getShortUrlId($len = 7) {
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
        $charsLen = 62;
        $key = '';

        for ($i = 0; $i < $len; $i++) {
            $key .= $chars[mt_rand() % $charsLen];
        }

        return $key;
    }
737645
public static function readline(StreamInterface $stream, $maxLength = null, $eol = PHP_EOL)
    {
        $buffer = '';
        $size = 0;
        $negEolLen = -strlen($eol);

        while (!$stream->eof()) {
            if (false === ($byte = $stream->read(1))) {
                return $buffer;
            }
            $buffer .= $byte;
            // Break when a new line is found or the max length - 1 is reached
            if (++$size == $maxLength || substr($buffer, $negEolLen) === $eol) {
                break;
            }
        }

        return $buffer;
    }
224827
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;
    }
481436
public function read($len = null)
    {

        // if $len is specified, we'll use that; otherwise, use the configured buffer size.
        if ($len === null) {
            $len = $this->bufferSize;
        }

        if (($data = $this->in->read($len)) !== -1) {
            // not all files end with a newline character, so we also need to check EOF
            if (!$this->in->eof()) {
                $notValidPart = strrchr($data, "\n");
                $notValidPartSize = strlen($notValidPart);

                if ($notValidPartSize > 1) {
                    // Block doesn't finish on a EOL
                    // Find the last EOL and forget all following stuff
                    $dataSize = strlen($data);
                    $validSize = $dataSize - $notValidPartSize + 1;

                    $data = substr($data, 0, $validSize);

                    // Rewind to the beginning of the forgotten stuff.
                    $this->in->skip(-$notValidPartSize + 1);
                }
            } // if !EOF
        }

        return $data;
    }
1187033
public function skip($n)
    {
        $start = $this->currentPosition;

        $ret = @fseek($this->stream, $n, SEEK_CUR);
        if ($ret === -1) {
            return -1;
        }

        $this->currentPosition = ftell($this->stream);

        if ($start > $this->currentPosition) {
            $skipped = $start - $this->currentPosition;
        } else {
            $skipped = $this->currentPosition - $start;
        }

        return $skipped;
    }
931020
protected function read($len)
    {
        $contents   = "";
        $clen       = 0;
        while (!feof($this->socket) && $clen < $len) {
            $read = fread($this->socket, $len - $clen);
            if ($read === false) {
                throw new \Erebot\Exception('Connection closed by proxy');
            }
            $contents  .= $read;
            $clen       = strlen($contents);
        }
        return $contents;
    }
750758
public function drawLine($len = 80)
    {
        if (is_string($len)) {
            $len = strlen($len);
        }

        $this->line(str_repeat('-', max($len, 80)));
    }
1070509
public function skip(int $n) : int
    {
        if ($n <= 0) {
            return 0;
        }

        $skipped = 0;
        $skipLimit = min(self::MAX_SKIP_BUFFER_SIZE, $n);
        while ($skipped < $n) {
            $buf = $this->read(min($skipLimit, $n - $skipped));
            if ($buf === null) {
                break;
            }
            $skipped += strlen($buf);
        }
        return $skipped;
    }
108362
public function readLine(int $length = 8192): string
    {
        return iconv($this->charset, 'UTF-8', $this->inputStream->readLine($length));
    }
1169694
protected function get_num_parts($len)
    {
        $min_l = min($len, $this->minPart);
        $max_l = max($len, $this->maxPart);

        $n = $len - $min_l + 1;
        $d = $max_l - $min_l;
        $m = $n - $d;

        $s1 = $m * ($d + 1);
        $s2 = $d * ($d + 1) / 2;
        $s = $s1 + $s2;

        return (int) $s;
    }
742763
public function readLine($maxLength = null)
    {
        $buffer = '';
        $size = 0;
        while (!$this->isConsumed()) {
            $byte = $this->read(1);
            $buffer .= $byte;
            // Break when a new line is found or the max length - 1 is reached
            if ($byte == PHP_EOL || ++$size == $maxLength - 1) {
                break;
            }
        }

        return $buffer;
    }
151893
public function readAll($len)
    {
        // return $this->read($len);

        $data = '';
        $got = 0;
        while (($got = TStringFuncFactory::create()->strlen($data)) < $len) {
            $data .= $this->read($len - $got);
        }

        return $data;
    }
244835
private function numberOfCommas($len)
    {
        $avg = (float) log($len, 6);
        $stdDev = (float) $avg / 6.000;

        return (int) round($this->gauss_ms($avg, $stdDev));
    }
1003324
public function readLine($length = null) {
        $this->openRead();
        if (empty($length)) {
            return fgets($this->stream);
        }
        return fgets($this->stream, $length);
    }
1297663
protected function firstLinesRaw($lineCount=20)
    {
        if ($this->firstLinesRaw !== null) {
            return $this->firstLinesRaw;
        }

        $this->lineReader->setFilePath($this->filePath);

        $lines = [];

        foreach ($this->lineReader as $i=>$line) {
            $lines[] = $line;

            if ($i >= $lineCount) {
                break;
            }
        }

        $this->lineReader->releaseHandle();

        $this->firstLinesRaw = implode("\n", $lines);

        return $this->firstLinesRaw;
    }