protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
-
- // Calculate header size
- $this->setHeaderSize(
- strlen(self::INDEX_MAGIC) +
- strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
- BaseFile::LENGTH_COUNT +
- strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
- );
-
- // Init counters and gaps array
- $this->initCountersGapsArray();
}
/**
$this->getIteratorInstance()->rewind();
// Then read it (see constructor for calculation)
- $data = $this->getIteratorInstance()->read($this->getHeaderSize());
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getHeaderSize()));
+ $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getIteratorInstance()->getHeaderSize()));
// Have all requested bytes been read?
- assert(strlen($data) == $this->getHeaderSize());
+ assert(strlen($data) == $this->getIteratorInstance()->getHeaderSize());
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Last character must be the separator
// Set iterator here
$this->setIteratorInstance($iteratorInstance);
+ // Calculate header size
+ $this->getIteratorInstance()->setHeaderSize(
+ strlen(self::INDEX_MAGIC) +
+ strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+ BaseFile::LENGTH_COUNT +
+ strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
+ );
+
+ // Init counters and gaps array
+ $this->getIteratorInstance()->initCountersGapsArray();
+
// Is the file's header initialized?
if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
// No, then create it (which may pre-allocate the index)