/** * Destroy tarball reader * * @return \Magento\Framework\Archive\Tar */ protected function _destroyReader() { if ($this->_reader instanceof \Magento\Framework\Archive\Helper\File) { $this->_reader->close(); $this->_reader = null; } return $this; }
/** * 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 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); } }