From 7ccb91667f8c4c3f95d8705f5986f86f5a2e350e Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Fri, 28 Feb 2014 10:30:12 +1100 Subject: [PATCH] Fallback to gzip functions when on Windows --- src/Composer/Downloader/GzipDownloader.php | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php index 61f92caf9..4444db369 100644 --- a/src/Composer/Downloader/GzipDownloader.php +++ b/src/Composer/Downloader/GzipDownloader.php @@ -36,15 +36,28 @@ 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)); - if (0 === $this->process->execute($command, $ignoredOutput)) { - return; + // 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; + } + + $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); + throw new \RuntimeException($processError); } - $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); - 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); } /**