Prewk\XmlStringStreamer\Parser\UniqueNode::prepareChunk PHP Method

prepareChunk() protected method

Decides whether we're to fetch more chunks from the stream or keep working with what we have.
protected prepareChunk ( Prewk\XmlStringStreamer\StreamInterface $stream ) : boolean
$stream Prewk\XmlStringStreamer\StreamInterface The stream provider
return boolean 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;
        }
    }