/** * Extracts a specific file and writes it's content * to the file specified with $destination. * * @param mixed $index index or name of the requested file * @param string $destination * @return boolean $success */ public function extract($index, $destination) { if (!$this->read) { $this->open(); $this->readContent(); } $header = $this->getFileInfo($index); // can not extract a folder if ($header['type'] != 'file') { return false; } // seek to offset $this->file->seek($header['offset']); $targetFile = new File($destination); // read data $n = floor($header['size'] / 512); for ($i = 0; $i < $n; $i++) { $content = $this->file->read(512); $targetFile->write($content, 512); } if (($header['size'] % 512) != 0) { $content = $this->file->read(512); $targetFile->write($content, ($header['size'] % 512)); } $targetFile->close(); if (function_exists('apache_get_version') || !@$targetFile->is_writable()) { @$targetFile->chmod(0777); } else { @$targetFile->chmod(0755); } if ($header['mtime']) { @$targetFile->touch($header['mtime']); } // check filesize if (filesize($destination) != $header['size']) { throw new SystemException("Could not untar file '".$header['filename']."' to '".$destination."'. Maybe disk quota exceeded in folder '".dirname($destination)."'."); } return true; }