/** * Decides whether we're to fetch more chunks from the stream or keep working with what we have. * @param StreamInterface $stream The stream provider * @return bool Keep working? */ protected function prepareChunk(StreamInterface $stream) { if ($this->hasSearchedUntilPos > -1 && $this->hasSearchedUntilPos < strlen($this->workingBlob) - 1) { // More work to do return true; } $chunk = $stream->getChunk(); if ($chunk === false) { // EOF if ($this->hasSearchedUntilPos === -1) { // EOF, but we haven't even started searching, special case that probably means we're dealing with a file of less size than the stream buffer // Therefore, keep looping return true; } return false; } else { // New chunk fetched if (!$this->firstNodeFound && !$this->options["extractContainer"]) { // Prevent a memory leak if we never find our first node, throw away our old stuff // but keep some letters to not cut off a first node $this->workingBlob = substr($this->workingBlob, -1 * strlen("<" . $this->options["uniqueNode"] . ">")) . $chunk; } else { $this->workingBlob .= $chunk; } return true; } }
/** * Decides whether we're to fetch more chunks from the stream or keep working with what we have. * @param StreamInterface $stream The stream provider * @return bool Keep working? */ protected function prepareChunk(StreamInterface $stream) { if ($this->hasSearchedUntilPos > -1 && $this->hasSearchedUntilPos < strlen($this->workingBlob) - 1) { // More work to do return true; } $chunk = $stream->getChunk(); if ($chunk === false) { // EOF if ($this->hasSearchedUntilPos === -1) { // EOF, but we haven't even started searching, special case that probably means we're dealing with a file of less size than the stream buffer // Therefore, keep looping return true; } return false; } else { // New chunk fetched $this->workingBlob .= $chunk; return true; } }
/** * The shave method must be able to request more data even though there isn't any more to fetch from the stream, this method wraps the getChunk call so that it returns true as long as there is XML data left * @param StreamInterface $stream The stream to read from * @return bool Returns whether there is more XML data or not */ protected function prepareChunk(StreamInterface $stream) { if (!$this->firstRun && is_null($this->shaved)) { // We're starting again after a flush $this->shaved = ""; return true; } else { if (is_null($this->shaved)) { $this->shaved = ""; } } $newChunk = $stream->getChunk(); if ($newChunk !== false) { $this->chunk .= $newChunk; return true; } else { if (trim($this->chunk) !== "" && $this->chunk !== $this->lastChunk) { // Update anti-freeze protection chunk $this->lastChunk = $this->chunk; // Continue return true; } } return false; }