Skip to content

Commit 5b52ae0

Browse files
committed
changed to gzdecode function
1 parent e7f4b6f commit 5b52ae0

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/GeoIPUpdater.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,10 @@ protected function updateMaxmindDatabase()
7575
*/
7676
protected function gzdecode($data)
7777
{
78-
do {
79-
$tempName = uniqid('temp ');
80-
} while (file_exists($tempName));
81-
82-
if (file_put_contents($tempName, $data)) {
83-
try {
84-
ob_start();
85-
@readgzfile($tempName);
86-
$uncompressed = ob_get_clean();
87-
} catch (Exception $e) {
88-
$ex = $e;
89-
}
90-
91-
unlink($tempName);
92-
93-
if (isset($ex)) {
94-
throw $ex;
95-
}
96-
97-
return $uncompressed;
78+
if (!function_exists('gzdecode')) {
79+
return gzinflate(substr($data, 10, -8));
9880
}
81+
82+
return gzdecode($data);
9983
}
10084
}

tests/GeoIPTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public function test_maxmind_database()
161161

162162
$this->assertEquals('United Kingdom', $geoip->getCountry());
163163

164+
$this->assertInstanceOf('GeoIp2\Model\City', $geoip->getRaw());
165+
164166
$geoip = $geoip->setIp($this->invalidIp);
165167

166168
$this->assertEquals([
@@ -209,6 +211,10 @@ public function test_ip_api()
209211

210212
$geoip = $geoip->setIp($this->invalidIp);
211213

214+
$this->assertArraySubset([
215+
'status' => 'fail',
216+
], $geoip->getRaw());
217+
212218
$this->assertEquals([
213219
'city' => null,
214220
'country' => null,

0 commit comments

Comments
 (0)