Extract zip file

@param string $archive path of archive
@param string $target
@param bool $deleteSource
@return Chee\Pclzip\Pclzip|false
431619
protected function extractZip($archive, $target, $deleteSource = false)
    {
        if (!$this->files->exists($target))
        {
            $this->files->makeDirectory($target, 0777, true);
        }

        $archive = new Pclzip($archive);

        if ($archive->extract(PCLZIP_OPT_PATH, $target) == 0)
        {
            $this->errors->add('extract_zip', $archive->error_string);
            return false;
        }

        if ($deleteSource)
            $this->files->delete($archive->zipname);

        return $archive;
    }
303214
protected function extractGzipFile($filename, $target)
    {
        $fileHandler = fopen($filename, 'rb');

        $bitReader = new BitReader($fileHandler);

        // read file header
        try {
            $fileHeader = FileHeader::createFromResource($filename, $fileHandler);
        } catch (Exception\IO\Input\FileCorruptedException $e) {
            throw $e;
        }

        // read compressed blocks
        $result = '';
        $isBlockFinal = false;

        while (false === $isBlockFinal) {
            $isBlockFinal = 1 === $bitReader->read(1);
            $compressionType = $bitReader->read(2);

            if (self::COMPRESSION_TYPE_NON_COMPRESSED === $compressionType) {
                // no compression
                $data = unpack("vlength/vlengthOneComplement", fread($fileHandler, 4));

                $result .= fread($fileHandler, $data['length']);
            } else {
                // compression
                if (self::COMPRESSION_TYPE_FIXED_HUFFMAN === $compressionType) {
                    list($literalsTree, $distancesTree) = $this->getFixedHuffmanTrees();
                } elseif (self::COMPRESSION_TYPE_DYNAMIC_HUFFMAN === $compressionType) {
                    list($literalsTree, $distancesTree) = $this->getDynamicHuffmanTrees($bitReader);
                } else {
                    throw new Exception\IO\Input\FileCorruptedException($filename);
                }

                $result .= $this->uncompressCompressedBlock($literalsTree, $distancesTree, $bitReader, $result);
            }

            $literalsTree = null;
            $distancesTree = null;
        }

        // check crc32
        $footer = unpack('Vcrc/Visize', fread($fileHandler, 8));
        if ($footer['crc'] !== crc32($result)) {
            throw new Exception\IO\Input\FileCorruptedException($filename);
        }

        fclose($fileHandler);

        // write file
        $outputFilename = $fileHeader->getOriginalFilename();
        if (empty($outputFilename)) {
            $outputFilename = pathinfo($filename, PATHINFO_FILENAME);
        }
        $location = $target.DIRECTORY_SEPARATOR.$outputFilename;
        file_put_contents($location, $result);

        return true;
    }
935014
public static function zipExtract(String $source, String $target = NULL) : Bool
    {
        $source = Info::rpath($source);
        $target = Info::rpath($target);

        $source = Base::suffix($source, '.zip');

        if( ! file_exists($source) )
        {
            throw new Exception\FileNotFoundException(NULL, $source);
        }

        if( empty($target) )
        {
            $target = Extension::remove($source);
        }

        $zip = new ZipArchive;

        if( $zip->open($source) === true )
        {
            $zip->extractTo($target);
            $zip->close();

            return true;
        }
        else
        {
            return false;
        }
    }
1154302
public function extract($archive, $destination)
	{
		if (!is_file($archive))
		{
			throw new \RuntimeException('Archive does not exist');
		}

		if ($this->hasNativeSupport())
		{
			return $this->extractNative($archive, $destination);
		}
		else
		{
			return $this->extractCustom($archive, $destination);
		}
	}
154563
public function copy($source, $target)
    {
        if (!is_dir($source)) {
            return copy($source, $target);
        }
        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        /** @var RecursiveDirectoryIterator $ri */
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
        $this->filesystem->ensureDirectoryExists($target);
        $result = true;
        foreach ($ri as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
            if ($file->isDir()) {
                $this->filesystem->ensureDirectoryExists($targetPath);
            } else {
                $result = $result && copy($file->getPathname(), $targetPath);
            }
        }
        return $result;
    }
1100752
public function extractZipFile($container, $path, $zip, $clean = false, $drop_path = '')
    {
        if ($clean) {
            try {
                // clear out anything in this directory
                $dir = static::addContainerToName($container, $path);
                FileUtilities::deleteTree($dir, true, false);
            } catch (\Exception $ex) {
                throw new InternalServerErrorException("Could not clean out existing directory $path.\n{$ex->getMessage()}");
            }
        }
        for ($i = 0; $i < $zip->numFiles; $i++) {
            $name = $zip->getNameIndex($i);
            if (empty($name)) {
                continue;
            }
            if (!empty($drop_path)) {
                $name = str_ireplace($drop_path, '', $name);
            }
            $fullPathName = $path . $name;
            if ('/' === substr($fullPathName, -1)) {
                $this->createFolder($container, $fullPathName, true, [], false);
            } else {
                $parent = FileUtilities::getParentFolder($fullPathName);
                if (!empty($parent)) {
                    $this->createFolder($container, $parent, true, [], false);
                }
                $content = $zip->getFromIndex($i);
                $this->writeFile($container, $fullPathName, $content);
            }
        }

        return [
            'name' => rtrim($path, DIRECTORY_SEPARATOR),
            'path' => $path,
            'type' => 'file'
        ];
    }
787774
static function copyFile($source, $target, $overwrite = true)
    {
        if (!file_exists($source)) return false;
        if (file_exists($target) && $overwrite == false) return false;
        elseif (file_exists($target) && $overwrite == true) {
            if (!unlink($target)) return false;
        }
        $targetDir = dirname($target);
        if (!self::createDirectory($targetDir)) return false;
        return copy($source, $target);
    }
746304
public static function RecursiveCopyDir($source, $target)
    {
        $source_dir = opendir($source);

        //Check if source directory exists
        if(!$source_dir)
        {
            return false;
        }

        //Create target directory in case it doesnt exist
        if(!file_exists($target))
        {
            self::MakeDir($target, 0755, true);
        }

        while(($item = readdir($source_dir)) !== false)
        {
            $source_full_path = $source . "/" . $item;
            $target_full_path = $target . "/" . $item;

            if($item != "." && $item != "..")
            {
                //copy source files
                if(is_file($source_full_path))
                {
                    if(!copy($source_full_path, $target_full_path))
                    {
                        return false;
                    }
                }
                else if(is_dir($source_full_path))
                {
                    self::RecursiveCopyDir($source_full_path, $target_full_path);
                }
            }
        }

        closedir($source_dir);

        return true;
    }
1097431
public function copy($source, $target)
    {
        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);

        if (!file_exists($target)) {
            mkdir($target, 0777, true);
        }

        foreach ($ri as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
            if ($file->isDir()) {
                if (!file_exists($targetPath)) {
                    mkdir($targetPath);
                }
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
837510
public function extract()
    {
        if ($this->extracted === null) {
            if ($this->source instanceof File) {
                $archiveFolder = tao_helpers_File::createTempDir();
                if (!is_dir($archiveFolder)) {
                    mkdir($archiveFolder);
                }
                $filename = $archiveFolder . basename($this->source->getPrefix());
                file_put_contents($filename, $this->source->read());
                $this->source = $filename;
            }

            if(!is_file($this->source)){	//ultimate verification
                throw new common_exception_Error("source ".$this->source." not a file");
            }

            $folder = tao_helpers_File::createTempDir();
            if (!is_dir($folder)) {
                mkdir($folder);
            }

            $zip = new ZipArchive();
            if ($zip->open($this->source) === true) {
                if (tao_helpers_File::checkWhetherArchiveIsBomb($zip)) {
                    throw new common_exception_Error(sprintf('Source %s seems to be a ZIP bomb', $this->source));
                }
                if($zip->extractTo($folder)){
                    $this->extracted = $folder;
                }
                $zip->close();
            }
        }

        return (string) $this->extracted;
    }
858618
protected function extractZip($zipPath)
    {
        $archive = new ZipArchive;

        $archive->open($zipPath);

        $archive->extractTo($this->command->path.'/spark-new');

        $archive->close();

        @unlink($zipPath);
    }
1253707
public function getFile( $fileName, $target = "" )
	{
		$this->connection->checkConnection();
		if( !$target )
			$target	= $fileName;
		return @ftp_get( $this->connection->getResource(), $target, $fileName, $this->connection->mode );
	}
1219864
protected function extractFormat($source, $target, FormatInterface $format)
    {
        $success = false;
        for ($i = 0, $methodsCount = count($this->methods); $i<$methodsCount && false === $success; $i++) {
            $method = $this->methods[$i];

            if ($method->isSupported() && $method->isFormatSupported($format)) {
                $success = $method->extract($source, $target, $format);
            }
        }

        return $success;
    }
589346
public function extract( $targetPath = NULL )
	{
		$counter	= 0;
		if( $targetPath )
		{
			$cwd	= getCwd();
			Folder_Editor::createFolder( $targetPath );
			chdir( $targetPath );
		}
		foreach( $this->folders as $folder )
			Folder_Editor::createFolder( $folder['name'] );
		foreach( $this->files as $file )
		{
			if( $folder = dirname( $file['name'] ) )
				Folder_Editor::createFolder( $folder );
			$counter	+= (int)(bool) File_Writer::save( $file['name'], $file['file'] );
		}
		if( $targetPath )
			chDir( $cwd );
		return $counter;
	}
167642
public static function copy($source, $target)
    {
        $source = Normalize::diskFullPath($source);
        $target = Normalize::diskFullPath($target);

        // check if target directory exist & create new if not
        $targetArray = explode(DIRECTORY_SEPARATOR, $target);
        array_pop($targetArray);
        $targetDir = implode(DIRECTORY_SEPARATOR, $targetArray);
        if (!Directory::exist($targetDir)) {
            Directory::create($targetDir, 0777);
        }

        return copy($source, $target);
    }
920332
public function unzip($file, $destinationPath)
    {
        if (!class_exists('\ZipArchive')) {
            throw new Error("Class ZipArchive does not installed. Cannot unzip the file.");
        }

        $zip = new \ZipArchive;
        $res = $zip->open($file);

        if ($res === TRUE) {

            $this->getFileManager()->mkdir($destinationPath);

            $zip->extractTo($destinationPath);
            $zip->close();

            return true;
        }

        return false;
    }
827545
def extract_zipfile(archive_name, destpath):
    ""
    archive = zipfile.ZipFile(archive_name)
    archive.extractall(destpath)