<commit_before><?php
namespace Chamilo\Libraries\File\Compression\Pclzip;

use Chamilo\Libraries\File\Compression\Filecompression;
use Chamilo\Libraries\File\Filesystem;
use PclZip;

/**
 * This class implements file compression and extraction using the PclZip library
 */
class PclzipFilecompression extends Filecompression
{

    public function get_supported_mimetypes()
    {
        return array(
            'application/x-zip-compressed', 
            'application/zip', 
            'multipart/x-zip', 
            'application/x-gzip', 
            'multipart/x-gzip');
    }

    public function is_supported_mimetype($mimetype)
    {
        return in_array($mimetype, $this->get_supported_mimetypes());
    }

    public function extract_file($file, $with_safe_names = true)
    {
        $dir = $this->create_temporary_directory();
        $pclzip = new PclZip($file);
        if ($pclzip->extract(PCLZIP_OPT_PATH, $dir) == 0)
        {
            print_r($pclzip->errorInfo());
            
            return false;
        }
        
        if ($with_safe_names)
        {
            Filesystem::create_safe_names($dir);
        }
        
        return $dir;
    }

    public function create_archive($path)
    {
        $fileName = $this->get_filename();
        $temporaryPath = $this->create_temporary_directory();
        
        if (! isset($fileName))
        {
            $fileName = Filesystem::create_unique_name($temporaryPath, uniqid() . '.zip');
        }
        
        $path = realpath($path);
        
        $archiveFile = $temporaryPath . $fileName;
        
        $fileList = Filesystem::get_directory_content($path, Filesystem::LIST_FILES, true);
        
        ini_set('memory_limit', '-1');
        
        $pclzip = new PclZip($archiveFile);
        $pclzip->add($fileList, PCLZIP_OPT_REMOVE_PATH, $path);
        
        return $archiveFile;
    }
}<commit_msg>[Libraries] PCLZip force temporary files<commit_after><?php
namespace Chamilo\Libraries\File\Compression\Pclzip;

use Chamilo\Libraries\File\Compression\Filecompression;
use Chamilo\Libraries\File\Filesystem;
use PclZip;

/**
 * This class implements file compression and extraction using the PclZip library
 */
class PclzipFilecompression extends Filecompression
{

    public function get_supported_mimetypes()
    {
        return array(
            'application/x-zip-compressed', 
            'application/zip', 
            'multipart/x-zip', 
            'application/x-gzip', 
            'multipart/x-gzip');
    }

    public function is_supported_mimetype($mimetype)
    {
        return in_array($mimetype, $this->get_supported_mimetypes());
    }

    public function extract_file($file, $with_safe_names = true)
    {
        $dir = $this->create_temporary_directory();
        $pclzip = new PclZip($file);
        if ($pclzip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_ADD_TEMP_FILE_ON) == 0)
        {
            print_r($pclzip->errorInfo());
            
            return false;
        }
        
        if ($with_safe_names)
        {
            Filesystem::create_safe_names($dir);
        }
        
        return $dir;
    }

    public function create_archive($path)
    {
        $fileName = $this->get_filename();
        $temporaryPath = $this->create_temporary_directory();
        
        if (! isset($fileName))
        {
            $fileName = Filesystem::create_unique_name($temporaryPath, uniqid() . '.zip');
        }
        
        $path = realpath($path);
        
        $archiveFile = $temporaryPath . $fileName;
        
        $fileList = Filesystem::get_directory_content($path, Filesystem::LIST_FILES, true);
        
        ini_set('memory_limit', '-1');
        
        $pclzip = new PclZip($archiveFile);
        $pclzip->add($fileList, PCLZIP_OPT_REMOVE_PATH, $path, PCLZIP_OPT_ADD_TEMP_FILE_ON);
        
        return $archiveFile;
    }
}
{'fraction_non_alphanumeric': 0.11635621331972441, 'fraction_numerical': 0.0010206685378923194, 'mean_word_length': 2.2157506152584086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6745223', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1203, 'n_words': 194}