public static decompress ( string $data ) : mixed | ||
$data | string | |
Résultat | mixed |
public static function decompress($data)
{
// Decompress the file
if (@file_exists($data)) {
$bz = bzopen($data, 'r');
$uncompressed = '';
// Read the uncompressed data.
while (!feof($bz)) {
$uncompressed .= bzread($bz, 4096);
}
// Close the Bzip2 compressed file and write
// the data to the uncompressed file.
bzclose($bz);
if (stripos($data, '.tbz2') !== false) {
$newFile = str_replace('.tbz2', '.tar', $data);
} else {
if (stripos($data, '.tbz') !== false) {
$newFile = str_replace('.tbz', '.tar', $data);
} else {
$newFile = str_replace('.bz2', '', $data);
}
}
file_put_contents($newFile, $uncompressed);
return $newFile;
// Else, decompress the string
} else {
return bzdecompress($data);
}
}
/** * Method to extract an archived and/or compressed file * * @param string $to * @return void */ public function extract($to = null) { if ($this->compression == 'bz') { $this->path = Compress\Bzip2::decompress($this->path); $this->archive = new \Archive_Tar($this->path); } else { if ($this->compression == 'gz') { $this->path = Compress\Gzip::decompress($this->path); $this->archive = new \Archive_Tar($this->path); } } $this->archive->extract(null !== $to ? $to : './'); }