/** * 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; }
/** * Overwritten Mage_Archive_Helper_File constructor with zlib extension check * @param string $filePath * @throws Mage_Exception */ public function __construct($filePath) { if (!function_exists('gzopen')) { throw new Mage_Exception('PHP Extensions "zlib" must be loaded.'); } parent::__construct($filePath); }
/** * 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); } }