Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  namespace MaxMind\Db\Reader;
   4  
   5  class Util
   6  {
   7      public static function read($stream, $offset, $numberOfBytes)
   8      {
   9          if ($numberOfBytes === 0) {
  10              return '';
  11          }
  12          if (fseek($stream, $offset) === 0) {
  13              $value = fread($stream, $numberOfBytes);
  14  
  15              // We check that the number of bytes read is equal to the number
  16              // asked for. We use ftell as getting the length of $value is
  17              // much slower.
  18              if (ftell($stream) - $offset === $numberOfBytes) {
  19                  return $value;
  20              }
  21          }
  22          throw new InvalidDatabaseException(
  23              'The MaxMind DB file contains bad data'
  24          );
  25      }
  26  }