]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 6 Jan 2021 19:59:09 +0000 (20:59 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 6 Jan 2021 19:59:09 +0000 (20:59 +0100)
- fixed bug which occured because the last block was counted twice. This
  happened when read() returns an empty (zero length) string which was not
  properly handled (maybe EOF reached).

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php

index 6a0cd6caad2dcd6afca9ba4b4db3a52ca6adb6ba..ac37fd24dbc04e479f284b7357a8eced9d76f317 100644 (file)
@@ -317,7 +317,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                        $endPosition = $idx * $minimumBlockLength + $minimumBlockLength;
 
                        // Mark start and end position as gap
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition));
                        $this->addGap($startPosition, $endPosition);
                }
 
@@ -791,18 +791,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                // Output message (as this may take some time)
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Analyzing file structure ... (this may take some time)'));
 
-               // First rewind to the begining
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
-               $this->rewind();
+               // First Seek to right after file header
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->seek(%d) ...', $this->getHeaderSize() + 1));
+               $this->seek($this->getHeaderSize() + 1);
 
                // Then try to load all entries
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Looping through file');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, looping through file ...', $this->getSeekPosition()));
                while ($this->isValid()) {
                        // Get current entry
                        $current = $this->getCurrentBlock();
 
                        // Go to next entry
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->readNextBlock() ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current=%s, calling this->readNextBlock() ...', $current));
                        $this->readNextBlock();
 
                        /*
@@ -881,7 +881,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
 
                        // Is the block empty?
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%d', strlen($block), $length));
-                       if (empty(trim($block, chr(0)))) {
+                       if (strlen($block) == 0) {
+                               // Read empty block, maybe EOF
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, block is empty, maybe EOF reached - BREAK!', $this->getSeekPosition()));
+                               break;
+                       } elseif (empty(trim($block, chr(0)))) {
                                // Mark it as empty
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->markCurrentBlockAsEmpty(%d) ...', $this->getSeekPosition(), $length));
                                $this->markCurrentBlockAsEmpty($length);