Browse Source

Merge pull request #4877 from cs278/zip-zlib-muddle

zlib suggest and fallback on non Windows
Jordi Boggiano 9 years ago
parent
commit
16215c1937
3 changed files with 22 additions and 9 deletions
  1. 2 1
      composer.json
  2. 1 1
      composer.lock
  3. 19 7
      src/Composer/Downloader/GzipDownloader.php

+ 2 - 1
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": {

+ 1 - 1
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": [
         {

+ 19 - 7
src/Composer/Downloader/GzipDownloader.php

@@ -48,18 +48,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);
     }
 
     /**
@@ -69,4 +70,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);
+    }
 }