diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php new file mode 100644 index 000000000..fc4cd98b2 --- /dev/null +++ b/src/Composer/Downloader/ZipDownloader.php @@ -0,0 +1,60 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Downloader; + +use Composer\Package\PackageInterface; + +/** + * @author Jordi Boggiano + */ +class ZipDownloader +{ + public function download(PackageInterface $package, $path) + { + $tmpName = tempnam(sys_get_temp_dir(), ''); + $this->downloadFile($package->getSourceUrl(), $tmpName); + + if (!file_exists($tmpName)) { + throw new \UnexpectedValueException($tmpName.' could not be created.'); + } + + $zipArchive = new ZipArchive(); + + if($zipArchive->open($tmpName) !== TRUE) { + $zipArchive->extractTo($path.'/'.$package->getName()); + $zipArchive->close(); + } + else { + throw new \UnexpectedValueException($tmpName.'is not a valid zip archive'); + } + } + + protected function downloadFile ($url, $path) + { + $file = fopen ($url, "rb"); + if ($file) { + $newf = fopen ($path, "wb"); + if ($newf) { + while(!feof($file)) { + fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); + } + } + } + if ($file) { + fclose($file); + } + if ($newf) { + fclose($newf); + } + } +} \ No newline at end of file