//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
}
+ /**
+ * Seeks to old position
+ *
+ * @return void
+ */
+ protected function seekToOldPosition () {
+ // Seek to currently ("old") saved position
+ $this->getIteratorInstance()->seek($this->getSeekPosition());
+ }
+
/**
* Writes data at given position
*
* @param $seekPosition Seek position
* @param $data Data to be written
+ * @param $flushHeader Whether to flush the header (default: flush)
* @return void
*/
- protected function writeData ($seekPosition, $data) {
+ protected function writeData ($seekPosition, $data, $flushHeader = TRUE) {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%s - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
// Write data at given position
// Update seek position
$this->updateSeekPosition();
- // Flush header
- $this->flushFileHeader();
+ // Flush the header?
+ if ($flushHeader === TRUE) {
+ // Flush header
+ $this->flushFileHeader();
+ } // END - if
// Seek to old position
$this->seekToOldPosition();
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
// Put all informations together
- $header = sprintf('%s%s',
+ $header = sprintf('%s%s%s%s',
// Magic
self::INDEX_MAGIC,
- // Separator position<->entries
+ // Separator header data
+ chr(self::SEPARATOR_HEADER_DATA),
+
+ // Total entries
+ str_pad($this->dec2hex($this->getCounter()), self::LENGTH_COUNT, '0', STR_PAD_LEFT),
+
+ // Separator header<->entries
chr(self::SEPARATOR_HEADER_ENTRIES)
);
// 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__));
}
);
// 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__));
}