You are here

private function Reader::findMetadataStart in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::findMetadataStart()
1 call to Reader::findMetadataStart()
Reader::__construct in includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php
Constructs a Reader for the MaxMind DB format. The file passed to it must be a valid MaxMind DB file such as a GeoIp2 database file.

File

includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php, line 233

Class

Reader
Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the <code>get</code> method.

Namespace

MaxMind\Db

Code

private function findMetadataStart($filename) {
  $handle = $this->fileHandle;
  $fstat = fstat($handle);
  $fileSize = $fstat['size'];
  $marker = self::$METADATA_START_MARKER;
  $markerLength = self::$METADATA_START_MARKER_LENGTH;
  for ($i = 0; $i < $fileSize - $markerLength + 1; $i++) {
    for ($j = 0; $j < $markerLength; $j++) {
      fseek($handle, $fileSize - $i - $j - 1);
      $matchBit = fgetc($handle);
      if ($matchBit != $marker[$markerLength - $j - 1]) {
        continue 2;
      }
    }
    return $fileSize - $i;
  }
  throw new InvalidDatabaseException("Error opening database file ({$filename}). " . 'Is this a valid MaxMind DB file?');
}