X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Fbinary%2Fclass_BaseBinaryFile.php;h=d2adfe87c170821c0672e1dc509384295cfaf5b1;hb=deb07dbc679f4cc7fe0e84eeb352f87f21ccf0aa;hp=2bfc27716044ad3d6b06233ee850cbe36439c17d;hpb=6dd6e82fe8514a88af39fbbec5c4e3a73956f308;p=core.git diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index 2bfc2771..d2adfe87 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -26,7 +26,7 @@ use \UnexpectedValueException; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -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); @@ -915,11 +919,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { // Left part is the actual block, right one the back-buffer data, if found //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray))); - //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true))); + /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true))); $this->setCurrentBlock($dataArray[0]); // Is back buffere data found? - if (!empty(trim($dataArray[1], chr(0)))) { + if (isset($dataArray[1]) && !empty(trim($dataArray[1], chr(0)))) { // Set back buffer //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->backBuffer=%s ...', $dataArray[1])); $this->setBackBuffer($dataArray[1]);