Introduced writeData() (low-level method).
authorRoland Haeder <roland@mxchange.org>
Sat, 17 May 2014 22:59:19 +0000 (00:59 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 17 May 2014 22:59:19 +0000 (00:59 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/main/stacker/file/class_BaseFileStack.php

index 8a31cfaf17dc3464f84a41065db152182461cb6a..dd8570c45185aeb0f202bb0452221f093ae3c27a 100644 (file)
@@ -209,7 +209,7 @@ class BaseFileStack extends BaseStacker {
                // The file's header should not be initialized here
                assert(!$this->isFileHeaderInitialized());
 
-               // Flush file header
+               // Simple flush file header which will create it.
                $this->flushFileHeader();
 
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
@@ -245,7 +245,23 @@ class BaseFileStack extends BaseStacker {
                );
 
                // Write it to disk (header is always at seek position 0)
-               $this->getIteratorInstance()->writeAtPosition(0, $header);
+               $this->writeData(0, $header);
+
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+       }
+
+       /**
+        * Writes data at given position
+        *
+        * @param       $seekPosition   Seek position
+        * @param       $data                   Data to be written
+        * @return      void
+        */
+       private function writeData ($seekPosition, $data) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%s - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
+
+               // Write data at given position
+               $this->getIteratorInstance()->writeAtPosition($seekPosition, $data);
 
                // Update seek position
                $this->updateSeekPosition();
@@ -284,11 +300,8 @@ class BaseFileStack extends BaseStacker {
                $seekPosition = $minLengthEntry * $this->getConfigInstance()->getConfigEntry('file_stack_pre_allocate_count');
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s', __METHOD__, __LINE__, $seekPosition));
 
-               // Now seek to the position
-               $seekStatus = $this->getIteratorInstance()->writeAtPosition($seekPosition, chr(0));
-
-               // Did it work?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekStatus=%d', __METHOD__, __LINE__, $seekStatus));
+               // Now simply write a NUL there. This will pre-allocate the file.
+               $this->writeData($seekPosition, chr(0));
 
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }