Beispiel #1
0
 /**
  * Unpack file by BZIP2 compressor.
  *
  * @param string $source
  * @param string $destination
  * @return string
  */
 public function unpack($source, $destination)
 {
     if (is_dir($destination)) {
         $file = $this->getFilename($source);
         $destination = $destination . $file;
     }
     $archiveReader = new Mage_Archive_Helper_File_Bz($source);
     $archiveReader->open('r');
     $fileWriter = new Mage_Archive_Helper_File($destination);
     $fileWriter->open('w');
     while (!$archiveReader->eof()) {
         $fileWriter->write($archiveReader->read());
     }
     return $destination;
 }
Beispiel #2
0
 /**
  * Extract next file from tarball by its $header information and save it to $destination
  *
  * @param array $fileHeader
  * @param string $destination
  */
 protected function _extractAndWriteFile($fileHeader, $destination)
 {
     $fileWriter = new Mage_Archive_Helper_File($destination);
     $fileWriter->open('w', $fileHeader['mode']);
     $archiveReader = $this->_getReader();
     $filesize = $fileHeader['size'];
     $bytesExtracted = 0;
     while ($filesize > $bytesExtracted && !$archiveReader->eof()) {
         $block = $archiveReader->read(self::TAR_BLOCK_SIZE);
         $nonExtractedBytesCount = $filesize - $bytesExtracted;
         $data = substr($block, 0, $nonExtractedBytesCount);
         $fileWriter->write($data);
         $bytesExtracted += strlen($block);
     }
 }