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

decompress() public static méthode

Static method to decompress data
public static decompress ( string $data ) : mixed
$data string
Résultat mixed
    public static function decompress($data)
    {
        // Decompress the file
        if (@file_exists($data)) {
            $gz = gzopen($data, 'r');
            $uncompressed = '';
            // Read the uncompressed data
            while (!feof($gz)) {
                $uncompressed .= gzread($gz, 4096);
            }
            // Close the Gzip compressed file and write
            // the data to the uncompressed file
            gzclose($gz);
            $newFile = stripos($data, '.tgz') !== false ? str_replace('.tgz', '.tar', $data) : str_replace('.gz', '', $data);
            file_put_contents($newFile, $uncompressed);
            return $newFile;
            // Else, decompress the string
        } else {
            return gzinflate(substr($data, 10));
        }
    }

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::decompress