X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Findex%2Ffile_stack%2Fclass_FileStackIndex.php;fp=inc%2Fclasses%2Fmain%2Findex%2Ffile_stack%2Fclass_FileStackIndex.php;h=9075e5c21ee3c8460eb7bd3fc9b9babdfc0d8eac;hp=307d39963ea64829cd974a1fed28c1283b98edb0;hb=a3fcf88a37aac86d61f3d9eeee9c0e16de10a604;hpb=0233ed850501e6327bf42dba56ecd17e40182c63 diff --git a/inc/classes/main/index/file_stack/class_FileStackIndex.php b/inc/classes/main/index/file_stack/class_FileStackIndex.php index 307d3996..9075e5c2 100644 --- a/inc/classes/main/index/file_stack/class_FileStackIndex.php +++ b/inc/classes/main/index/file_stack/class_FileStackIndex.php @@ -57,7 +57,37 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable { * @return void */ public function addHashToIndex ($groupId, array $data) { - $this->partialStub('groupId=' . $groupId . ',data=' . print_r($data, TRUE)); + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH])); + + // Raw data been written to the file + $rawData = sprintf('%s%s%s%s%s%s%s', + $groupId, + self::SEPARATOR_GROUP_HASH, + hex2bin($data[BaseFileStack::ARRAY_INDEX_HASH]), + self::SEPARATOR_HASH_GAP_POSITION, + $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], + self::SEPARATOR_GAP_LENGTH, + $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH] + ); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%s', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData))); + + // Search for next free gap + $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData)); + + // Gap position cannot be smaller than header length + 1 + assert($gapPosition > $this->getIteratorInstance()->getHeaderSize()); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gapPosition=%s', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $gapPosition)); + + // Then write the data at that gap + $this->getIteratorInstance()->writeData($gapPosition, $rawData); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%s - EXIT!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData))); } /**