public function readBytes($length, $position = null)
    {
        $length = (int) $length;
        if ($position !== null) {
            // check if needed bytes are available in the current buffer
            if (!($position >= $this->position && $position < $this->position + $this->bufferLength)) {
                $this->reset($position, $length);
                $offset = $this->offset;
            } else {
                $offset = $position - $this->position;
            }
        } else {
            $offset = $this->offset;
        }

        if (($offset + $length) > $this->bufferLength &&
            ((!$this->increaseLength($length)) || ($offset + $length) > $this->bufferLength)
        ) {
            return false;
        }

        $bytes = \substr($this->buffer, $offset, $length);
        $this->offset = $offset + $length;

        return $bytes;
    }
public function readBytes($length, $position = null)
    {
        $length = (int) $length;
        if ($position !== null) {
            // check if needed bytes are available in the current buffer
            if (!($position >= $this->position && $position < $this->position + $this->bufferLength)) {
                $this->reset($position, $length);
                $offset = $this->offset;
            } else {
                $offset = $position - $this->position;
            }
        } else {
            $offset = $this->offset;
        }

        if (($offset + $length) > $this->bufferLength &&
            ((!$this->increaseLength($length)) || ($offset + $length) > $this->bufferLength)
        ) {
            return false;
        }

        $bytes = \substr($this->buffer, $offset, $length);
        $this->offset = $offset + $length;

        return $bytes;
    }
public function readBytes ( $ length , $ position = null ) { $ length = ( int ) $ length ; if ( $ position !== null ) { // check if needed bytes are available in the current buffer if ( ! ( $ position >= $ this -> position && $ position < $ this -> position + $ this -> bufferLength ) ) { $ this -> reset ( $ position , $ length ) ; $ offset = $ this -> offset ; } else { $ offset = $ position - $ this -> position ; } } else { $ offset = $ this -> offset ; } if ( ( $ offset + $ length ) > $ this -> bufferLength && ( ( ! $ this -> increaseLength ( $ length ) ) || ( $ offset + $ length ) > $ this -> bufferLength ) ) { return false ; } $ bytes = \ substr ( $ this -> buffer , $ offset , $ length ) ; $ this -> offset = $ offset + $ length ; return $ bytes ; }
Read bytes from the current or a specific offset position and set the internal pointer to the next byte.

If the position is invalid the method will return false.

If the $position parameter is set to null the value of $this->offset will be used.

@param int $length
@param int|null $position
@return string
Read bytes from the current or a specific offset position and set the internal pointer to the next byte .