You are here

protected function CompressionFilter::zipDecode in Backup and Migrate 5.0.x

Gzip decode a file.

Parameters

\Drupal\backup_migrate\Core\File\BackupFileReadableInterface $from:

\Drupal\backup_migrate\Core\File\BackupFileWritableInterface $to:

Return value

bool

1 call to CompressionFilter::zipDecode()
CompressionFilter::beforeRestore in src/Core/Filter/CompressionFilter.php
Run on a restore.

File

src/Core/Filter/CompressionFilter.php, line 325

Class

CompressionFilter

Namespace

Drupal\backup_migrate\Core\Filter

Code

protected function zipDecode(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
  $success = FALSE;
  if (class_exists('ZipArchive')) {
    $zip = new \ZipArchive();
    if ($zip
      ->open(\Drupal::service('file_system')
      ->realpath($from
      ->realpath()))) {
      $filename = $zip
        ->getNameIndex(0);
      if ($fp_in = $zip
        ->getStream($filename)) {
        while (!feof($fp_in)) {
          $to
            ->write(fread($fp_in, 1024 * 512));
        }
        fclose($fp_in);
        $success = $to
          ->close();
      }
    }
    return $success;
  }
}