+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+ }
+
+ /**
+ * Pre-allocates file (if enabled) with some space for later faster write access.
+ *
+ * @param $type Type of the file
+ * @return void
+ * @throws InvalidArgumentException If a parameter is empty
+ * @throws BadMethodCallException If this->stackInstance is not properly set
+ */
+ protected function preAllocateFileByTypeLength (string $type, int $minimumBlockLength) {
+ // Is it enabled?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength));
+ if (empty($type)) {
+ // Empty type
+ throw new InvalidArgumentException('Parameter "type" is empty');
+ } elseif ($minimumBlockLength < 1) {
+ // Invalid block length
+ throw new InvalidArgumentException(sprintf('Parameter minimumBlockLength=%d is not valid', $minimumBlockLength));
+ } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
+ // Don't continue here.
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.'));
+ return;
+ }
+
+ // Get file size
+ $fileSize = $this->getFileSize();
+
+ // Calulcate seek position
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minimumBlockLength=%d,fileSize=%d', $minimumBlockLength, $fileSize));
+ $seekPosition = $this->getHeaderSize() + $minimumBlockLength * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count') + $fileSize ;
+
+ // Now simply write a NUL there. This will pre-allocate the file.
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,NUL) ...', $seekPosition));
+ $this->writeAtPosition($seekPosition, chr(0));
+
+ // Is the seek position zero?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%d', $fileSize));
+ if ($fileSize == 0) {
+ // Mark file as gaps-only
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->markGapsOnly(%s,%d) ...', $type, $minimumBlockLength));
+ $this->markFileGapsOnly($type, $minimumBlockLength);
+ } else {
+ // Analyze file structure
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->analyzeFileStructure() ...');
+ $this->analyzeFileStructure();
+ }
+
+ // Rewind seek position
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
+ $this->rewind();