/** * Unpack file by GZ 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 \Magento\Framework\Archive\Helper\File\Gz($source); $archiveReader->open('r'); $fileWriter = new \Magento\Framework\Archive\Helper\File($destination); $fileWriter->open('w'); while (!$archiveReader->eof()) { $fileWriter->write($archiveReader->read()); } return $destination; }
/** * Extract next file from tarball by its $header information and save it to $destination * * @param array $fileHeader * @param string $destination * @return void */ protected function _extractAndWriteFile($fileHeader, $destination) { $fileWriter = new \Magento\Framework\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); } }