3 namespace Drupal\Core\Archiver;
6 * Defines a archiver implementation for .tar files.
8 class Tar implements ArchiverInterface {
11 * The underlying ArchiveTar instance that does the heavy lifting.
13 * @var \Drupal\Core\Archiver\ArchiveTar
18 * Constructs a Tar object.
20 * @param string $file_path
21 * The full system path of the archive to manipulate. Only local files
22 * are supported. If the file does not yet exist, it will be created if
25 * @throws \Drupal\Core\Archiver\ArchiverException
27 public function __construct($file_path) {
28 $this->tar = new ArchiveTar($file_path);
34 public function add($file_path) {
35 $this->tar->add($file_path);
43 public function remove($file_path) {
44 // @todo Archive_Tar doesn't have a remove operation
45 // so we'll have to simulate it somehow, probably by
46 // creating a new archive with everything but the removed
55 public function extract($path, array $files = []) {
57 $this->tar->extractList($files, $path);
60 $this->tar->extract($path);
69 public function listContents() {
71 foreach ($this->tar->listContent() as $file_data) {
72 $files[] = $file_data['filename'];
78 * Retrieves the tar engine itself.
80 * In some cases it may be necessary to directly access the underlying
81 * Archive_Tar object for implementation-specific logic. This is for advanced
82 * use only as it is not shared by other implementations of ArchiveInterface.
85 * The Archive_Tar object used by this object.
87 public function getArchive() {