Exemple #1
0
 /**
  * Pack file by GZ compressor.
  *
  * @param string $source
  * @param string $destination
  * @return string
  */
 public function pack($source, $destination)
 {
     $fileReader = new \Magento\Framework\Archive\Helper\File($source);
     $fileReader->open('r');
     $archiveWriter = new \Magento\Framework\Archive\Helper\File\Gz($destination);
     $archiveWriter->open('wb9');
     while (!$fileReader->eof()) {
         $archiveWriter->write($fileReader->read());
     }
     $fileReader->close();
     $archiveWriter->close();
     return $destination;
 }
Exemple #2
0
 /**
  * Write current file to tarball
  *
  * @return void
  */
 protected function _packAndWriteCurrentFile()
 {
     $archiveWriter = $this->_getWriter();
     $archiveWriter->write($this->_composeHeader());
     $currentFile = $this->_getCurrentFile();
     $fileSize = 0;
     if (is_file($currentFile) && !is_link($currentFile)) {
         $fileReader = new \Magento\Framework\Archive\Helper\File($currentFile);
         $fileReader->open('r');
         while (!$fileReader->eof()) {
             $archiveWriter->write($fileReader->read());
         }
         $fileReader->close();
         $fileSize = filesize($currentFile);
     }
     $appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
     $archiveWriter->write(str_repeat("", $appendZerosCount));
 }