Ejemplo n.º 1
0
 /**
  * Initialize tarball reader
  *
  * @return \Magento\Framework\Archive\Tar
  */
 protected function _initReader()
 {
     $this->_reader = new \Magento\Framework\Archive\Helper\File($this->_getCurrentFile());
     $this->_reader->open('r');
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * 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);
     }
 }