]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/iterator/io/class_FileIoIterator.php
EOF needs to be checked again.
[core.git] / inc / classes / main / iterator / io / class_FileIoIterator.php
index 736280a3db49ab13ac4dd14c089d71fd3e1e4393..9ef4801d2a25dc6ab807492ea9c4744b3056afc6 100644 (file)
@@ -150,9 +150,16 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato
 
                // Wait until a entry/block separator has been found
                $data = $this->getBackBuffer();
-               while (!$this->getBlockInstance()->isBlockSeparatorFound($data)) {
+               while (($this->getPointerInstance()->isEndOfFileReached()) && (!$this->getBlockInstance()->isBlockSeparatorFound($data))) {
                        // Then read the block
                        $data .= $this->read($length);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('data()=' . strlen($data));
+               } // END - if
+
+               // EOF reached?
+               if ($this->getPointerInstance()->isEndOfFileReached()) {
+                       // Then abort here silently
+                       return;
                } // END - if
 
                /*
@@ -162,7 +169,7 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato
                $this->initBackBuffer();
 
                // Separate data
-               $dataArray = explode($this->getBlockInstance()->getBlockSeparator(), $data);
+               $dataArray = explode(self::getBlockSeparator(), $data);
 
                // Left part is the actual block, right one the back-buffer data
                $this->setCurrentBlock($dataArray[0]);
@@ -201,8 +208,17 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato
                // If some bytes could be read, all is fine
                $isValid = ((is_string($data)) && (strlen($data) > 0));
 
-               // Seek back to old position
-               $this->seek($seekPosition);
+               // Get header size
+               $headerSize = $this->getBlockInstance()->getHeaderSize();
+
+               // Is the seek position at or beyond the header?
+               if ($seekPosition >= $headerSize) {
+                       // Seek back to old position
+                       $this->seek($seekPosition);
+               } else {
+                       // Seek directly behind the header
+                       $this->seek($headerSize);
+               }
 
                // Return result
                return $isValid;