Pop\Compress\Gzip::compress PHP Méthode

compress() public static méthode

Static method to compress data
public static compress ( string $data, integer $level = 9, integer $mode = FORCE_GZIP ) : mixed
$data string
$level integer
$mode integer
Résultat mixed
    public static function compress($data, $level = 9, $mode = FORCE_GZIP)
    {
        // Compress the file
        if (file_exists($data)) {
            $fullpath = realpath($data);
            $data = file_get_contents($data);
            // Create the new Gzip file resource, write data and close it
            $gzResource = fopen($fullpath . '.gz', 'w');
            fwrite($gzResource, gzencode($data, $level, $mode));
            fclose($gzResource);
            return $fullpath . '.gz';
            // Else, compress the string
        } else {
            return gzencode($data, $level, $mode);
        }
    }

Usage Example

Exemple #1
0
 public function testGzipWithFile()
 {
     if (function_exists('gzcompress')) {
         $compressed = Gzip::compress(__DIR__ . '/../tmp/access.txt');
         $this->fileExists(__DIR__ . '/../tmp/access.txt.gz');
         $decompressed = Gzip::decompress($compressed);
         $this->fileExists(__DIR__ . '/../tmp/access.txt');
         if (file_exists(__DIR__ . '/../tmp/access.txt.gz')) {
             unlink(__DIR__ . '/../tmp/access.txt.gz');
         }
     }
 }
All Usage Examples Of Pop\Compress\Gzip::compress