You are here

protected function CompressionFilter::_gzipEncode in Backup and Migrate 8.4

Gzip encode a file.

Parameters

\BackupMigrate\Core\File\BackupFileReadableInterface $from:

\BackupMigrate\Core\File\BackupFileWritableInterface $to:

Return value

bool

1 call to CompressionFilter::_gzipEncode()
CompressionFilter::afterBackup in lib/backup_migrate_core/src/Filter/CompressionFilter.php
Run on a backup.

File

lib/backup_migrate_core/src/Filter/CompressionFilter.php, line 199

Class

CompressionFilter
Class CompressionFilter.

Namespace

BackupMigrate\Core\Filter

Code

protected function _gzipEncode(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
  $success = FALSE;
  if (!$success && function_exists("gzopen")) {
    if (($fp_out = gzopen($to
      ->realpath(), 'wb9')) && $from
      ->openForRead()) {
      while ($data = $from
        ->readBytes(1024 * 512)) {
        gzwrite($fp_out, $data);
      }
      $success = TRUE;
      $from
        ->close();
      gzclose($fp_out);

      // Get the compressed filesize and set it.
      $fileszc = filesize(drupal_realpath($to
        ->realpath()));
      $to
        ->setMeta('filesize', $fileszc);
    }
  }
  return $success;
}