/** * Return literal length data located at the end of the stream. * * @return mixed Null if no literal data found, or an array with these * keys: * - binary: (boolean) True if this is a literal8. * - length: (integer) Length of the literal. */ public function getLiteralLength() { $this->_stream->end(-1); if ($this->_stream->peek() === '}') { $literal_data = $this->_stream->getString($this->_stream->search('{', true) - 1); $literal_len = substr($literal_data, 2, -1); if (is_numeric($literal_len)) { return array('binary' => $literal_data[0] === '~', 'length' => intval($literal_len)); } } return null; }
/** * Find the location of the end of the header text. * * @return array 1st element: Header position, 2nd element: Length of * trailing EOL. */ protected function _findHeader() { $i = 0; while (!$this->_stream->eof()) { $data = $this->_stream->substring(0, 8192); $hdr_pos = strpos($data, "\r\n\r\n"); if ($hdr_pos !== false) { return array($hdr_pos + $i * 8192, 4); } $hdr_pos = strpos($data, "\n\n"); if ($hdr_pos !== false) { return array($hdr_pos + $i * 8192, 2); } $i++; } $this->_stream->end(); return array($this->_stream->pos(), 0); }
/** * Flush the remaining entries left in the iterator. * * @param boolean $return If true, return entries. Only returns entries * on the current level. * @param boolean $sublevel Only flush items in current sublevel? * * @return array The entries if $return is true. */ public function flushIterator($return = true, $sublevel = true) { $out = array(); if ($return) { $this->_nextModify = array('level' => $sublevel ? $this->_level : 0, 'out' => array()); $this->next(); $out = $this->_nextModify['out']; $this->_nextModify = array(); } elseif ($sublevel && $this->_level) { $this->_nextModify = array('level' => $this->_level); $this->next(); $this->_nextModify = array(); } else { $this->_stream->end(); $this->_stream->getChar(); $this->_current = $this->_key = $this->_level = false; } return $out; }