From 8debdf8764a629e32180e77e0bef59ed70ff2d34 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 4 Feb 2016 00:34:01 +0000 Subject: [PATCH 1/2] Zip extension does not provide zlib support --- composer.json | 3 ++- composer.lock | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8fcd1ea93..f45775853 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ } }, "suggest": { - "ext-zip": "Enabling the zip extension allows you to unzip archives, and allows gzip compression of all internet traffic", + "ext-zip": "Enabling the zip extension allows you to unzip archives", + "ext-zlib": "Allow gzip compression of HTTP requests", "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages" }, "autoload": { diff --git a/composer.lock b/composer.lock index caeba6397..31543e65c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "fdf4b487fa59607376721ebec4ff4783", + "hash": "31b3c13c89f8d6c810637ca1fe8fc6ae", "content-hash": "454148e20b837d9755dee7862f9c7a5d", "packages": [ { From e4877473cf4d47d22952418452b5798276bd1558 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 4 Feb 2016 00:39:31 +0000 Subject: [PATCH 2/2] Fallback to zlib extension to unpack gzip on non Windows systems --- src/Composer/Downloader/GzipDownloader.php | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php index ae7d7f17a..11f2f7f33 100644 --- a/src/Composer/Downloader/GzipDownloader.php +++ b/src/Composer/Downloader/GzipDownloader.php @@ -47,18 +47,19 @@ class GzipDownloader extends ArchiveDownloader return; } + if (extension_loaded('zlib')) { + // Fallback to using the PHP extension. + $this->extractUsingExt($file, $targetFilepath); + + return; + } + $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); throw new \RuntimeException($processError); } // Windows 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); + $this->extractUsingExt($file, $targetFilepath); } /** @@ -68,4 +69,15 @@ class GzipDownloader extends ArchiveDownloader { return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME); } + + private function extractUsingExt($file, $targetFilepath) + { + $archiveFile = gzopen($file, 'rb'); + $targetFile = fopen($targetFilepath, 'wb'); + while ($string = gzread($archiveFile, 4096)) { + fwrite($targetFile, $string, strlen($string)); + } + gzclose($archiveFile); + fclose($targetFile); + } }