X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;h=56c3b99d4b7539cfce89f814448953fa90d6f68d;hp=c14743b32f84900e82a496edc02e97711f8e407d;hb=a863937b246c06e143d147fe4108543056971472;hpb=510fd302ecdfcb218f0c093a8dfc628682a8d20b diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index c14743b3..56c3b99d 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -76,7 +76,7 @@ class BaseFileStack extends BaseStacker { * * @return void */ - private function readFileHeader () { + protected function readFileHeader () { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__)); // First rewind to beginning as the header sits at the beginning ... @@ -108,26 +108,29 @@ class BaseFileStack extends BaseStacker { * 1 => total entries * 2 => current seek position */ - $this->header = explode(chr(self::SEPARATOR_HEADER_DATA), $data); + $header = explode(chr(self::SEPARATOR_HEADER_DATA), $data); + + // Set header here + $this->setHeader($header); // Check if the array has only 3 elements - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] header(%d)=%s', __METHOD__, __LINE__, count($this->header), print_r($this->header, TRUE))); - assert(count($this->header) == 3); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] header(%d)=%s', __METHOD__, __LINE__, count($header), print_r($header, TRUE))); + assert(count($header) == 3); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__)); // Check magic - assert($this->header[0] == self::STACK_MAGIC); + assert($header[0] == self::STACK_MAGIC); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__)); // Check length of count and seek position - assert(strlen($this->header[1]) == self::LENGTH_COUNT); + assert(strlen($header[1]) == self::LENGTH_COUNT); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__)); - assert(strlen($this->header[2]) == self::LENGTH_POSITION); + assert(strlen($header[2]) == self::LENGTH_POSITION); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__)); // Decode count and seek position - $this->header[1] = hex2bin($this->header[1]); - $this->header[2] = hex2bin($this->header[2]); + $header[1] = hex2bin($header[1]); + $header[2] = hex2bin($header[2]); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } @@ -137,7 +140,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 @@ -162,7 +165,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__)); } @@ -186,6 +189,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', __METHOD__, __LINE__, print_r($current, TRUE))); + } // END - while + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } @@ -195,13 +213,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)); // Is the instance implementing the right interface? assert($iteratorInstance instanceof SeekableWritableFileIterator); @@ -234,6 +253,19 @@ 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 *