src/JsonStream.php
public function read($length)
    {
        $length = max(0, (int) $length);
        $encoder = $this->getEncoder();

        while (strlen($this->buffer) < $length && $encoder->valid()) {
            $this->buffer .= $encoder->current();
            $encoder->next();
        }

        if (strlen($this->buffer) > $length || $encoder->valid()) {
            $output = substr($this->buffer, 0, $length);
            $this->buffer = substr($this->buffer, $length);
        } else {
            $output = (string) $this->buffer;
            $this->buffer = null;
        }

        $this->cursor += strlen($output);

        return $output;
    }
public function read($length)
    {
        $length = max(0, (int) $length);
        $encoder = $this->getEncoder();

        while (strlen($this->buffer) < $length && $encoder->valid()) {
            $this->buffer .= $encoder->current();
            $encoder->next();
        }

        if (strlen($this->buffer) > $length || $encoder->valid()) {
            $output = substr($this->buffer, 0, $length);
            $this->buffer = substr($this->buffer, $length);
        } else {
            $output = (string) $this->buffer;
            $this->buffer = null;
        }

        $this->cursor += strlen($output);

        return $output;
    }
public function read ( $ length ) { $ length = max ( 0 , ( int ) $ length ) ; $ encoder = $ this -> getEncoder ( ) ; while ( strlen ( $ this -> buffer ) < $ length && $ encoder -> valid ( ) ) { $ this -> buffer .= $ encoder -> current ( ) ; $ encoder -> next ( ) ; } if ( strlen ( $ this -> buffer ) > $ length || $ encoder -> valid ( ) ) { $ output = substr ( $ this -> buffer , 0 , $ length ) ; $ this -> buffer = substr ( $ this -> buffer , $ length ) ; } else { $ output = ( string ) $ this -> buffer ; $ this -> buffer = null ; } $ this -> cursor += strlen ( $ output ) ; return $ output ; }
Returns the given number of bytes from the JSON stream.

The underlying value is encoded into JSON until enough bytes have been
generated to fulfill the requested number of bytes. The extraneous bytes are
then buffered for the next read from the JSON stream. The stream may return
fewer number of bytes if the entire value has been encoded and there are no
more bytes to return.

@param int $length The number of bytes to return
@return string The bytes read from the JSON stream
Returns the given number of bytes from the JSON stream .