Skip to content

Commit 539755c

Browse files
authored
Merge pull request #189 from xPaw/fstat
Use fstat for file size, reuse it for finding metadata start
2 parents d7aecba + c7a2cc8 commit 539755c

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/MaxMind/Db/Reader.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public function __construct(string $database)
9494
}
9595
$this->fileHandle = $fileHandle;
9696

97-
$fileSize = @filesize($database);
98-
if ($fileSize === false) {
97+
$fstat = fstat($fileHandle);
98+
if ($fstat === false) {
9999
throw new \UnexpectedValueException(
100100
"Error determining the size of \"$database\"."
101101
);
102102
}
103-
$this->fileSize = $fileSize;
103+
$this->fileSize = $fstat['size'];
104104

105105
$start = $this->findMetadataStart($database);
106106
$metadataDecoder = new Decoder($this->fileHandle, $start);
@@ -332,13 +332,7 @@ private function resolveDataPointer(int $pointer)
332332
private function findMetadataStart(string $filename): int
333333
{
334334
$handle = $this->fileHandle;
335-
$fstat = fstat($handle);
336-
if ($fstat === false) {
337-
throw new InvalidDatabaseException(
338-
"Error getting file information ($filename)."
339-
);
340-
}
341-
$fileSize = $fstat['size'];
335+
$fileSize = $this->fileSize;
342336
$marker = self::$METADATA_START_MARKER;
343337
$markerLength = self::$METADATA_START_MARKER_LENGTH;
344338

0 commit comments

Comments
 (0)