1
0
Fork 0

Fallback to gzip functions when on Windows

pull/2765/head
Pavel Puchkin 2014-02-28 10:30:12 +11:00
parent c598fdb0f5
commit 7ccb91667f
1 changed files with 19 additions and 6 deletions

View File

@ -36,8 +36,11 @@ class GzipDownloader extends ArchiveDownloader
protected function extract($file, $path)
{
$targetFile = $path . '/' . basename(substr($file, 0, -3));
$command = 'gzip -cd ' . escapeshellarg($file) . ' > ' . escapeshellarg($targetFile);
$targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3));
// Try to use gunzip on *nix
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$command = 'gzip -cd ' . escapeshellarg($file) . ' > ' . escapeshellarg($targetFilepath);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
@ -47,6 +50,16 @@ class GzipDownloader extends ArchiveDownloader
throw new \RuntimeException($processError);
}
// Gzip version of PHP has built-in support of gzip functions
$archiveFile = gzopen($file, 'rb');
$targetFile = fopen($targetFilepath, 'wb');
while ($string = gzread($archiveFile, 4096)) {
fwrite($targetFile, $string, strlen($string));
}
gzclose($archiveFile);
fclose($targetFile);
}
/**
* {@inheritdoc}
*/