Creates an archive via Phar library
@param array $files
@param $archiveFileName
@return bool
763848
protected static function createArchiveForPhar(array $files, $archiveFileName)
    {
        if (preg_match('~^(.+)\.(tar\.(gz|bz2))$~i', $archiveFileName, $match)) {
            $ext = $match[2];
            $basename = $match[1];
        } else {
            $ext = pathinfo($archiveFileName, PATHINFO_EXTENSION);
            $basename = dirname($archiveFileName).'/'.basename($archiveFileName, '.'.$ext);
        }
        $tar = new PharData($basename.'.tar', 0, null, Phar::TAR);

        try {
            foreach ($files as $localName => $filename) {
                if (is_null($filename)) {
                    if (!in_array($localName, ['/', ''], true)) {
                        if ($tar->addEmptyDir($localName) === false) {
                            return false;
                        }
                    }
                } else {
                    if ($tar->addFile($filename, $localName) === false) {
                        return false;
                    }
                }
            }
        } catch (Exception $e) {
            return false;
        }

        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $tar->compress(Phar::GZ, $ext);
                break;
            case 'bz2':
            case 'tbz2':
                $tar->compress(Phar::BZ2, $ext);
                break;
        }
        $tar = null;

        return count($files);
    }
655873
public function publishAndPropagate(array $files = array(), $extension = null, $before = [])
    {

        $container            = $this->assetFactory->container($this->position);
        $applicationContainer = $this->assetFactory->container('antares/foundation::application');

        if (empty($files)) {
            return $container;
        }
        if (!is_null($extension)) {
            $this->extension = $extension;
        }

        foreach ($files as $file) {
            $fileRealPath = $file->getRealPath();

            if ($fileRealPath !== false) {
                $name      = $this->extension . DIRECTORY_SEPARATOR . $file->getRelativePathname();
                $published = $this->symlinker->publish($name, $fileRealPath);

                if (!in_array($file->getExtension(), ['css', 'js']) or $published === false) {
                    continue;
                }
            } else {
                $published = $file->getRelativePathname();
            }

            $basename        = str_replace('\\', '/', $published);
            $sluggedBaseName = str_slug($file->getBasename());

            if ($file->getExtension() === 'css') {
                $applicationContainer->style($sluggedBaseName, $basename);
            } else {
                $container->add($sluggedBaseName, $basename, [], $before);
            }
        }
        return $container;
    }
527684
public function create($name)
    {
        $this->setArchiveName($name);
        $this->getArchiver()->open($this->getArchiveName(), \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
        return $this;
    }
261957
public static function createArchive(array $files, $archiveFileName){
        $zip = new ZipArchive();
        $result = $zip->open($archiveFileName, ZipArchive::CREATE);
        if ($result !== true)
            throw new Exception('ZipArchive error: '.$result);
        foreach ($files as $localName => $fileName) {
            if ($fileName === null) {
                if ($zip->addEmptyDir($localName) === false)
                    return false;
            } else {
                if ($zip->addFile($fileName, $localName) === false)
                    return false;
            }
        }
        $zip->close();

        return count($files);
    }
427878
public function getFileData($fileName)
    {
        if (!isset($this->filesData[$fileName]))
            return false;

        return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'],
            $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false);
    }
411577
public function createArchive()
    {
        if ($this->hasHead()) {
            $command = 'git archive -o ' . $this->getFilename() . ' HEAD 2>&1';
            exec($command, $output, $returnValue);

            return $returnValue === 0;
        }

        throw new GitHeadNotAvailable('No Git HEAD present to create an archive from.');
    }
591347
public function add_file_from_string($localname, $contents) {
        if ($this->emptyziphack) {
            $this->close();
            $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding);
        }

        if (!isset($this->za)) {
            return false;
        }

        $localname = trim($localname, '/'); // No leading slashes in archives!
        $localname = $this->mangle_pathname($localname);

        if ($localname === '') {
            // Sorry - conversion failed badly.
            return false;
        }

        if ($this->usedmem > 2097151) {
            // This prevents running out of memory when adding many large files using strings.
            $this->close();
            $res = $this->open($this->archivepathname, file_archive::OPEN, $this->encoding);
            if ($res !== true) {
                print_error('cannotopenzip');
            }
        }
        $this->usedmem += strlen($contents);

        if (!$this->za->addFromString($localname, $contents)) {
            return false;
        }
        $this->modified = true;
        return true;
    }
691691
public function downloadAction($filename)
    {
        $pathname = $this->getArchiver()->buildPathname($filename);

        if (!is_readable($pathname)) {
            throw $this->createNotFoundException(sprintf('Image archive "%s" is not readable.', $pathname));
        }

        return new BinaryFileResponse($pathname);
    }
343065
protected function filterZipFiles(ZipArchive $archive, array $ignore = [], array $force = [])
    {
        $dirName = $archive->getNameIndex(0);
        $return = [];
        $numFiles = $archive->getNumFiles();
        for ($i = 0; $i < $numFiles; ++$i) {
            $stat = $archive->statIndex($i);
            $return[] = $stat['name'];
        }
        $that = $this;
        $filter = array_filter($return, function ($var) use ($ignore, $force, $dirName, $that) {
            return !$that->isIgnored($var, $ignore, $force, $dirName);
        });

        return array_values($filter);
    }
654428
protected Archive openArchive(File zipFilename) throws IOException {
        try {
            return openArchive(zipFilename, contextUseOptimizedZip);
        } catch (IOException ioe) {
            if (ioe instanceof ZipFileIndex.ZipFormatException) {
                return openArchive(zipFilename, false);
            } else {
                throw ioe;
            }
        }
    }
1116662
private function createZipBackup() {
		if (class_exists ( \ZipArchive::class )) {
			$zip = new \ZipArchive ();
			$file_name = $this->file_name . '.zip';
			if ($zip->open ( $file_name, \ZipArchive::CREATE ) === TRUE) {
				$zip->addFile ( $this->file_name, basename ( $this->file_name ) );
				$zip->close ();
				
				@unlink ( $this->file_name );
				$this->file_name = $file_name;
			}
		} else {
			echo "ZipArchive missing class ";
		}
	}
1365700
public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
    {
        $updatedFiles = $model->$fileAttrName;

        foreach ($files as $file) {

            $log = (new FileLog)->create([
                'model_id' => $model->id,
                'model_name' => $folderName,
                'file_original_name' => $file->getClientOriginalName(),
            ]);

            $systemFileName = $this->createSystemFileName($log, $file);
            $filePath = $this->createFilePath($folderName, $systemFileName);
            $folderPath = $this->createFilePath($folderName);

            Storage::put(
                $filePath,
                file_get_contents($file->path())
            );

            $log->fill([
                'file_path' => $filePath,
                'file_system_name' => $systemFileName
            ])->save();

            if ($width)
                $this->imageResize($width, $file, $filePath);

            $updatedFiles[] = [
                'file_log_id' => $log->id,
                'path' => asset($log->file_path),
                'file_original_name' => $log->file_original_name
            ];
        }

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
1373489
public function addFiles($fileOrFiles)
    {
        $files_list = self::createFilesList($fileOrFiles);
        if (empty($files_list))
            throw new InvalidArgumentException('Files list is empty!');
        $result = $this->archive->addFiles($files_list);
        $this->scanArchive();
        return $result;
    }
1354811
public function create()
    {
        $folder = $this->getBackupFolder();

        $files = $this->backupFiles($folder);
        $db = $this->backupDatabase($folder);

        $resultFilename = $this->getBackupFilename();
        $archiveFile = dirname($folder) . DIRECTORY_SEPARATOR . $resultFilename . '.tar';

        // Create new archive
        $archive = new \PharData($archiveFile);

        // add folder
        $archive->buildFromDirectory($folder);

        // Remove temp directory
        FileHelper::removeDirectory($folder);

        return $archiveFile;
    }
847979
protected function extractArchive($archiveFile)
    {
        $archiveDir    = dirname($archiveFile);
        $archiveObj    = new ZipArchive();
        $archiveHandle = $archiveObj->open($archiveFile);
        if (true !== $archiveHandle) {
            return array('error' => __('Could not open archive'));
        }

        if (!$archiveObj->extractTo($archiveDir)) {
            $archiveObj->close();
            return array('error' => __('Could not extract archive'));
        }
        $archiveObj->close();
        return $archiveDir;
    }
595635
protected function unzipArchive($file = '', $targetDir = '', $deleteZipArchive = true) : bool
    {
        if (empty($file) || ! File::exists($file)) {
            throw new \InvalidArgumentException("Archive [{$file}] cannot be found or is empty.");
        }

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

        if (! $res) {
            throw new \Exception("Cannot open zip archive [{$file}].");
        }

        if (empty($targetDir)) {
            $extracted = $zip->extractTo(File::dirname($file));
        } else {
            $extracted = $zip->extractTo($targetDir);
        }

        $zip->close();

        if ($extracted && $deleteZipArchive === true) {
            File::delete($file);
        }

        return true;
    }
1295656
public function createArchive($options = array(), $nameArchive = null, $mode = 'create')
    {
        $options = array_merge($options, ['target_public_id' => $nameArchive, 'mode' => $mode]);
        return $this->getUploader()->create_archive($options);
    }