1 <?php
2
3 namespace MaxMind\Db\Reader;
4
5 use MaxMind\Db\Reader\InvalidDatabaseException;
6
7 class Util
8 {
9 public static function read($stream, $offset, $numberOfBytes)
10 {
11 if ($numberOfBytes == 0) {
12 return '';
13 }
14 if (fseek($stream, $offset) == 0) {
15 $value = fread($stream, $numberOfBytes);
16
17
18
19
20 if (ftell($stream) - $offset === $numberOfBytes) {
21 return $value;
22 }
23 }
24 throw new InvalidDatabaseException(
25 "The MaxMind DB file contains bad data"
26 );
27 }
28 }
29