protected function CompressionFilter::zipEncode in Backup and Migrate 5.0.x
Zip encode a file.
Parameters
\Drupal\backup_migrate\Core\File\BackupFileReadableInterface $from:
\Drupal\backup_migrate\Core\File\BackupFileWritableInterface $to:
Return value
bool
1 call to CompressionFilter::zipEncode()
- CompressionFilter::afterBackup in src/
Core/ Filter/ CompressionFilter.php - Run on a backup.
File
- src/
Core/ Filter/ CompressionFilter.php, line 299
Class
Namespace
Drupal\backup_migrate\Core\FilterCode
protected function zipEncode(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
$success = FALSE;
if (class_exists('ZipArchive')) {
$zip = new \ZipArchive();
$res = $zip
->open(\Drupal::service('file_system')
->realpath($to
->realpath()), constant("ZipArchive::CREATE"));
if ($res === TRUE) {
$zip
->addFile(\Drupal::service('file_system')
->realpath($from
->realpath()), $from
->getFullName());
}
$success = $zip
->close();
}
// Get the compressed filesize and set it.
$fileszc = filesize(\Drupal::service('file_system')
->realpath($to
->realpath()));
$to
->setMeta('filesize', $fileszc);
return $success;
}