X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;h=d16068d32d80ef3245a390e2f8ba0a626de8b49b;hp=5aa1c39b3fb4cf0defb84e9b019b539279b98af1;hb=4af01023fc4b9ffc4c7174264dbff53966aecc91;hpb=82845d401adc07626618b74bf155951bcc68e280 diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index 5aa1c39b..d16068d3 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 * @@ -140,7 +120,7 @@ class BaseFileStack extends BaseStacker { * * @return void */ - private function flushFileHeader () { + protected function flushFileHeader () { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__)); // Put all informations together @@ -165,7 +145,7 @@ class BaseFileStack extends BaseStacker { ); // Write it to disk (header is always at seek position 0) - $this->writeData(0, $header); + $this->writeData(0, $header, FALSE); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } @@ -189,6 +169,21 @@ class BaseFileStack extends BaseStacker { // 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()->valid()) { + // Go to next entry + $this->getIteratorInstance()->next(); + + // Get current entry + $current = $this->getIteratorInstance()->current(); + + // Simply output it + self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current(%s)=%s', __METHOD__, __LINE__, strlen($current), print_r($current, TRUE))); + } // END - while + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } @@ -198,13 +193,14 @@ class BaseFileStack extends BaseStacker { * @param $fileName File name of this stack * @param $type Type of this stack (e.g. url_source for URL sources) * @return void + * @todo Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file. */ protected function initFileStack ($fileName, $type) { - // Get a file i/o pointer instance for stack file - $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName)); + // Get a stack file instance + $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileName)); // Get iterator instance - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($pointerInstance)); + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($fileInstance, $this)); // Is the instance implementing the right interface? assert($iteratorInstance instanceof SeekableWritableFileIterator); @@ -237,19 +233,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 * @@ -424,6 +407,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]