MDL-65763 lib: Upgrade MixMind DB reader lib to 1.4.1
[moodle.git] / lib / maxmind / MaxMind / Db / Reader / Util.php
CommitLineData
eacc36a2
DP
1<?php
2
3namespace MaxMind\Db\Reader;
4
eacc36a2
DP
5class Util
6{
7 public static function read($stream, $offset, $numberOfBytes)
8 {
b55260fc 9 if ($numberOfBytes === 0) {
eacc36a2
DP
10 return '';
11 }
b55260fc 12 if (fseek($stream, $offset) === 0) {
eacc36a2
DP
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(
b55260fc 23 'The MaxMind DB file contains bad data'
eacc36a2
DP
24 );
25 }
26}