Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GzipDownloader.php

class GzipDownloader

GZip archive downloader.

@author Pavel Puchkin <i@neoascetic.me>

Hierarchy

  • class \Composer\Downloader\FileDownloader implements \Composer\Downloader\DownloaderInterface, \Composer\Downloader\ChangeReportInterface
    • class \Composer\Downloader\ArchiveDownloader extends \Composer\Downloader\FileDownloader
      • class \Composer\Downloader\GzipDownloader extends \Composer\Downloader\ArchiveDownloader

Expanded class hierarchy of GzipDownloader

File

vendor/composer/composer/src/Composer/Downloader/GzipDownloader.php, line 25

Namespace

Composer\Downloader
View source
class GzipDownloader extends ArchiveDownloader {
    protected function extract(PackageInterface $package, string $file, string $path) : PromiseInterface {
        $filename = pathinfo(parse_url(strtr((string) $package->getDistUrl(), '\\', '/'), PHP_URL_PATH), PATHINFO_FILENAME);
        $targetFilepath = $path . DIRECTORY_SEPARATOR . $filename;
        // Try to use gunzip on *nix
        if (!Platform::isWindows()) {
            $command = [
                'sh',
                '-c',
                'gzip -cd -- "$0" > "$1"',
                $file,
                $targetFilepath,
            ];
            if (0 === $this->process
                ->execute($command, $ignoredOutput)) {
                return \React\Promise\resolve(null);
            }
            if (extension_loaded('zlib')) {
                // Fallback to using the PHP extension.
                $this->extractUsingExt($file, $targetFilepath);
                return \React\Promise\resolve(null);
            }
            $processError = 'Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process
                ->getErrorOutput();
            throw new \RuntimeException($processError);
        }
        // Windows version of PHP has built-in support of gzip functions
        $this->extractUsingExt($file, $targetFilepath);
        return \React\Promise\resolve(null);
    }
    private function extractUsingExt(string $file, string $targetFilepath) : void {
        $archiveFile = gzopen($file, 'rb');
        $targetFile = fopen($targetFilepath, 'wb');
        while ($string = gzread($archiveFile, 4096)) {
            fwrite($targetFile, $string, Platform::strlen($string));
        }
        gzclose($archiveFile);
        fclose($targetFile);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ArchiveDownloader::$cleanupExecuted protected property
ArchiveDownloader::cleanup public function @inheritDoc Overrides FileDownloader::cleanup
ArchiveDownloader::getInstallOperationAppendix protected function @inheritDoc Overrides FileDownloader::getInstallOperationAppendix
ArchiveDownloader::install public function @inheritDoc Overrides FileDownloader::install
ArchiveDownloader::prepare public function @inheritDoc Overrides FileDownloader::prepare
FileDownloader::$additionalCleanupPaths private property @var array&lt;string, string[]&gt; Map of package name to list of paths
FileDownloader::$cache protected property @var ?Cache
FileDownloader::$config protected property @var Config
FileDownloader::$downloadMetadata public static property @private
@internal
FileDownloader::$eventDispatcher protected property @var ?EventDispatcher
FileDownloader::$filesystem protected property @var Filesystem
FileDownloader::$httpDownloader protected property @var HttpDownloader
FileDownloader::$io protected property @var IOInterface
FileDownloader::$lastCacheWrites private property
FileDownloader::$process protected property @var ProcessExecutor
FileDownloader::$responseHeaders public static property Collects response headers when running on GH Actions
FileDownloader::addCleanupPath protected function
FileDownloader::clearLastCacheWrite protected function
FileDownloader::download public function @inheritDoc Overrides DownloaderInterface::download 2
FileDownloader::getDistPath protected function
FileDownloader::getFileName protected function Gets file name for specific package
FileDownloader::getInstallationSource public function @inheritDoc Overrides DownloaderInterface::getInstallationSource
FileDownloader::getLocalChanges public function @inheritDoc Overrides ChangeReportInterface::getLocalChanges
FileDownloader::processUrl protected function Process the download url
FileDownloader::remove public function @inheritDoc Overrides DownloaderInterface::remove 1
FileDownloader::removeCleanupPath protected function
FileDownloader::update public function @inheritDoc Overrides DownloaderInterface::update
FileDownloader::__construct public function Constructor.
GzipDownloader::extract protected function Extract file to directory Overrides ArchiveDownloader::extract
GzipDownloader::extractUsingExt private function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal