1 backup.class.inc public Backup::decompress(BackupFile $file, $format = self::COMPRESSION_GZIP, $delete_original = FALSE)

Decompress a backup file with gzip.

Return value

bool|BackupFile: The newly decompressed file as BackupFile object. FALSE if failure.

File

core/includes/backup/backup.class.inc, line 321
Contains the Backup base class.

Class

Backup
Base class for creating backups.

Code

public function decompress(BackupFile $file, $format = self::COMPRESSION_GZIP, $delete_original = FALSE) {
  // Only gzip compression supported currently.
  if ($format !== self::COMPRESSION_GZIP) {
    return FALSE;
  }

  // If the file is not compressed, nothing to do here.
  if ($file->lastExtension() !== 'gz') {
    return $file;
  }

  $success = FALSE;
  $decompressed_file = clone $file;
  $decompressed_file->popExtension();

  $source = $file->filePath();
  $destination = $decompressed_file->filePath();

  if (function_exists('gzopen')) {
    $fp_out = fopen($destination, 'wb');
    $fp_in = gzopen($source, 'rb');
    if ($fp_out && $fp_in) {
      while (!feof($fp_in)) {
        fwrite($fp_out, gzread($fp_in, 1024 * 512));
      }
      $success = TRUE;
    }
    @gzclose($fp_in);
    @fclose($fp_out);
  }

  if ($success && $delete_original) {
    file_unmanaged_delete($source);
  }

  return $success ? $decompressed_file : FALSE;
}