Skip to content

Commit

Permalink
uncompress downloaded database to tmp file and fast cope it to target…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
peter-gribanov committed Jun 19, 2017
1 parent 0592a38 commit be0b4e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Command/UpdateDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->title('Update the GeoIP2 database');
$this->stopwatch->start('update');

$tmp = sys_get_temp_dir().DIRECTORY_SEPARATOR.basename($target);
$tmp_zip = sys_get_temp_dir().DIRECTORY_SEPARATOR.basename(parse_url($url, PHP_URL_PATH));
$tmp_unzip = sys_get_temp_dir().DIRECTORY_SEPARATOR. basename($target);

$io->comment(sprintf('Beginning download of file: %s', $url));

file_put_contents($tmp, fopen($url, 'rb'));
file_put_contents($tmp_zip, fopen($url, 'rb'));

$io->comment('Download complete');
$io->comment('De-compressing file');

$this->fs->mkdir(dirname($target), 0777);
$this->compressor->uncompress($tmp, $target);
$this->fs->chmod($target, 0777);
$this->compressor->uncompress($tmp_zip, $tmp_unzip);

$io->comment('Decompression complete');

$this->fs->copy($tmp_unzip, $target, true);
$this->fs->chmod($target, 0777);
$this->fs->remove([$tmp_zip, $tmp_unzip]);

$io->success('Finished downloading');

$this->stopwatch($io, $this->stopwatch->stop('update'));
Expand Down

0 comments on commit be0b4e1

Please sign in to comment.