X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;h=8e3ae4d8e11267a82923ec8e2381da7f5d61a312;hp=01193aab761de4e2eadbda4216d3100bafcbeede;hb=0af07e30d2e346b21cbb57b53c7550ce93baac06;hpb=6d54ef031eb27d1b9a46ce92f39a3c9b19633eb3 diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index 01193aab..8e3ae4d8 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -27,26 +27,6 @@ class BaseFileStack extends BaseStacker { */ const STACK_MAGIC = 'STACKv0.1'; - /** - * Separator for header data - */ - const SEPARATOR_HEADER_DATA = 0x01; - - /** - * Separator header->entries - */ - const SEPARATOR_HEADER_ENTRIES = 0x02; - - /** - * Separator hash->name - */ - const SEPARATOR_HASH_NAME = 0x03; - - /** - * Length of name - */ - const LENGTH_NAME = 10; - /** * Protected constructor * @@ -75,6 +55,7 @@ class BaseFileStack extends BaseStacker { * Reads the file header * * @return void + * @todo To hard assertions here, better rewrite them to exceptions */ protected function readFileHeader () { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__)); @@ -170,40 +151,6 @@ class BaseFileStack extends BaseStacker { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } - /** - * Analyzes entries in stack file. This will count all found (and valid) - * entries, mark invalid as damaged and count gaps ("fragmentation"). If - * only gaps are found, the file is considered as "virgin" (no entries). - * - * @return void - */ - private function analyzeFile () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__)); - - // Make sure the file is initialized - assert($this->isFileInitialized()); - - // Init counters and gaps array - $this->initCountersGapsArray(); - - // Output message (as this may take some time) - self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__)); - - // First rewind to the begining - $this->getIteratorInstance()->rewind(); - - // Then try to load all entries - while ($this->getIteratorInstance()->next()) { - // Get current entry - $current = $this->getIteratorInstance()->current(); - - // Simply output it - self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current=%s', __METHOD__, __LINE__, print_r($current, TRUE))); - } // END - while - - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); - } - /** * Initializes this file-based stack. * @@ -217,7 +164,7 @@ class BaseFileStack extends BaseStacker { $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileName)); // Get iterator instance - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($fileInstance)); + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($fileInstance, $this)); // Is the instance implementing the right interface? assert($iteratorInstance instanceof SeekableWritableFileIterator); @@ -238,7 +185,7 @@ class BaseFileStack extends BaseStacker { $this->readFileHeader(); // Count all entries in file - $this->analyzeFile(); + $this->getIteratorInstance()->analyzeFile(); /* * Get stack index instance. This can be used for faster @@ -250,19 +197,6 @@ class BaseFileStack extends BaseStacker { $this->setIndexInstance($indexInstance); } - /** - * Calculates minimum length for one entry - * - * @return $length Minimum length for one entry - */ - protected function caluclateMinimumFileEntryLength () { - // Calulcate it - $length = self::getHashLength() + strlen(self::SEPARATOR_HASH_NAME) + self::LENGTH_NAME + 1; - - // Return it - return $length; - } - /** * Adds a value to given stack * @@ -437,6 +371,19 @@ class BaseFileStack extends BaseStacker { // Now, simply return the found count value, this must be up-to-date then! return $this->getCounter(); } + + /** + * Calculates minimum length for one entry/block + * + * @return $length Minimum length for one entry/block + */ + public function caluclateMinimumBlockLength () { + // Calulcate it + $length = self::getHashLength() + strlen(chr(self::SEPARATOR_HASH_NAME)) + self::LENGTH_NAME + 1 + strlen(self::getBlockSeparator()); + + // Return it + return $length; + } } // [EOF]