]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/stacker/file/class_BaseFileStack.php
These 3 methods are now moved to BaseFile.
[core.git] / inc / classes / main / stacker / file / class_BaseFileStack.php
index 8a9abe0bb15d934cd299a6e60b19781f419be06b..abbcc775c66ea1430307cd72c894015f3a4f9a46 100644 (file)
@@ -36,19 +36,6 @@ class BaseFileStack extends BaseStacker {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Calculate header size
-               $this->setHeaderSize(
-                       strlen(self::STACK_MAGIC) +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
-                       BaseFile::LENGTH_COUNT +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
-                       BaseFile::LENGTH_POSITION +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
-               );
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
        }
 
        /**
@@ -64,11 +51,11 @@ class BaseFileStack extends BaseStacker {
                $this->getIteratorInstance()->rewind();
 
                // Then read it (see constructor for calculation)
-               $data = $this->getIteratorInstance()->read($this->getHeaderSize());
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getHeaderSize()));
+               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getIteratorInstance()->getHeaderSize()));
 
                // Have all requested bytes been read?
-               assert(strlen($data) == $this->getHeaderSize());
+               assert(strlen($data) == $this->getIteratorInstance()->getHeaderSize());
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
 
                // Last character must be the separator
@@ -172,6 +159,19 @@ class BaseFileStack extends BaseStacker {
                // Set iterator here
                $this->setIteratorInstance($iteratorInstance);
 
+               // Calculate header size
+               $this->getIteratorInstance()->setHeaderSize(
+                       strlen(self::STACK_MAGIC) +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+                       BaseFile::LENGTH_COUNT +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+                       BaseFile::LENGTH_POSITION +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
+               );
+
+               // Init counters and gaps array
+               $this->getIteratorInstance()->initCountersGapsArray();
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
                        // No, then create it (which may pre-allocate the stack)