]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/file_directories/class_BaseFile.php
Fixed: Fatal error: Access to undeclared static property: BaseFrameworkSystem::$hashL...
[core.git] / inc / classes / main / file_directories / class_BaseFile.php
index c96a4440ee551d14e6833d5b879775d9fc310cea..806745d11c2a8716d35a7cda0ac08ec80005baa8 100644 (file)
@@ -67,10 +67,17 @@ class BaseFile extends BaseFrameworkSystem {
         */
        const LENGTH_TYPE = 20;
 
+       //***** Array elements for 'gaps' array *****
+
+       /**
+        * Start of gap
+        */
+       const GAPS_INDEX_START = 'start';
+
        /**
-        * Length of output from hash()
+        * End of gap
         */
-       private static $hashLength = NULL;
+       const GAPS_INDEX_END = 'end';
 
        /**
         * Counter for total entries
@@ -152,7 +159,7 @@ y    * @return      void
         *
         * @return      void
         */
-       protected function initCountersGapsArray () {
+       public function initCountersGapsArray () {
                // Init counter and seek position
                $this->setCounter(0);
                $this->setSeekPosition(0);
@@ -209,7 +216,7 @@ y    * @return      void
         * @param       $headerSize             Size of file header
         * @return      void
         */
-       protected final function setHeaderSize ($headerSize) {
+       public final function setHeaderSize ($headerSize) {
                // Set it
                $this->headerSize = $headerSize;
        }
@@ -219,7 +226,7 @@ y    * @return      void
         *
         * @return      $totalEntries   Size of file header
         */
-       protected final function getHeade () {
+       public final function getHeader () {
                // Get it
                return $this->header;
        }
@@ -230,7 +237,7 @@ y    * @return      void
         * @param       $header         Array for a file header
         * @return      void
         */
-       protected final function setHeader (array $header) {
+       public final function setHeader (array $header) {
                // Set it
                $this->header = $header;
        }
@@ -261,11 +268,11 @@ y  * @return      void
         *
         * @return      void
         */
-       protected function updateSeekPosition () {
+       public function updateSeekPosition () {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // Get key (= seek position)
-               $seekPosition = $this->getIteratorInstance()->key();
+               $seekPosition = $this->key();
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Setting seekPosition=%s', __METHOD__, __LINE__, $seekPosition));
 
                // And set it here
@@ -280,14 +287,14 @@ y  * @return      void
         *
         * @return      void
         */
-       protected function rewineUpdateSeekPosition () {
+       protected function rewindUpdateSeekPosition () {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // flushFileHeader must be callable
                assert(is_callable(array($this, 'flushFileHeader')));
 
                // Seek to beginning of file
-               $this->getIteratorInstance()->rewind();
+               $this->rewind();
 
                // And update seek position ...
                $this->updateSeekPosition();
@@ -307,7 +314,7 @@ y    * @return      void
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // Seek to currently ("old") saved position
-               $this->getIteratorInstance()->seek($this->getSeekPosition());
+               $this->seek($this->getSeekPosition());
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
        }
@@ -456,6 +463,23 @@ y   * @return      void
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }
 
+       /**
+        * Marks the currently loaded block as empty (with length of the block)
+        *
+        * @param       $length         Length of the block
+        * @return      void
+        */
+       protected function markCurrentBlockAsEmpty ($length) {
+               // Get current seek position
+               $currentPosition = $this->key();
+
+               // Now add it as gap entry
+               array_push($this->gaps, array(
+                       self::GAPS_INDEX_START  => ($currentPosition - $length),
+                       self::GAPS_INDEX_END    => $currentPosition,
+               ));
+       }
+
        /**
         * Checks whether the file header is initialized
         *
@@ -532,7 +556,7 @@ y    * @return      void
                $this->flushFileHeader();
 
                // Rewind seek position (to beginning of file) and update/flush file header
-               $this->rewineUpdateSeekPosition();
+               $this->rewindUpdateSeekPosition();
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
        }
@@ -570,7 +594,7 @@ y    * @return      void
                $this->writeData($seekPosition, chr(0));
 
                // Rewind seek position (to beginning of file) and update/flush file header
-               $this->rewineUpdateSeekPosition();
+               $this->rewindUpdateSeekPosition();
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }
@@ -722,7 +746,6 @@ y    * @return      void
         * Advances to next "block" of bytes
         *
         * @return      void
-        * @todo        This method will load large but empty files in a whole
         */
        public function next () {
                // Is there nothing to read?
@@ -740,17 +763,37 @@ y  * @return      void
                // Short be more than zero!
                assert($length > 0);
 
-               // Wait until a entry/block separator has been found
+               // Read possibly back-buffered bytes from previous call of next().
                $data = $this->getBackBuffer();
+
+               /*
+                * Read until a entry/block separator has been found. The next read
+                * "block" may not fit, so this loop will continue until the EOB or EOF
+                * has been reached whatever comes first.
+                */
                while ((!$this->isEndOfFileReached()) && (!self::isBlockSeparatorFound($data))) {
-                       // Then read the block
-                       $data .= $this->read($length);
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('data()=' . strlen($data));
+                       // Then read the next possible block
+                       $block = $this->read($length);
+
+                       // Is it all empty?
+                       if (strlen(trim($block)) == 0) {
+                               // Mark this block as empty
+                               $this->markCurrentBlockAsEmpty($length);
+
+                               // Skip to next block
+                               continue;
+                       } // END - if
+
+                       // At this block then
+                       $data .= $block;
+
+                       // A debug message
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] data()=%s', __FUNCTION__, __LINE__, strlen($data)));
                } // END - if
 
                // EOF reached?
                if ($this->isEndOfFileReached()) {
-                       // Set whole data as current block
+                       // Set whole data as current read block
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('Calling setCurrentBlock(' . strlen($data) . ') ...');
                        $this->setCurrentBlock($data);