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);
}
}
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'); } } }