+ /**
+ * Creates the file-stack's header
+ *
+ * @return void
+ */
+ private function createFileHeader () {
+ // The file's header should not be initialized here
+ assert(!$this->isFileHeaderInitialized());
+
+ // Init counter
+ $this->getIteratorInstance()->initCounter();
+
+ // Flush file header
+ $this->flushFileHeader();
+ }
+
+ /**
+ * Flushes the file header
+ *
+ * @return void
+ */
+ private function flushFileHeader () {
+ // Put all informations together
+ $header = sprintf('%s%s%s%s%s',
+ // Magic
+ self::STACK_MAGIC,
+
+ // Separator magic<->count
+ chr(self::SEPARATOR_MAGIC_COUNT),
+
+ // Total entries (will be zero) and pad it to 20 chars
+ str_pad($this->dec2hex($this->getIteratorInstance()->getCount()), self::COUNT_LENGTH, '0', STR_PAD_LEFT),
+
+ // Position (will be zero)
+ str_pad($this->dec2hex(0, 2), self::COUNT_POSITION, '0', STR_PAD_LEFT),
+
+ // Separator position<->entries
+ chr(self::SEPARATOR_SEEK_POS_ENTRIES)
+ );
+
+ // Write it to disk
+ $this->getIteratorInstance()->writeAtPosition(0, $header);
+ }
+