class Tar

Same name in this branch
  1. 10 core/modules/system/src/Plugin/Archiver/Tar.php \Drupal\system\Plugin\Archiver\Tar
Same name and namespace in other branches
  1. 9 core/modules/system/src/Plugin/Archiver/Tar.php \Drupal\system\Plugin\Archiver\Tar
  2. 9 core/lib/Drupal/Core/Archiver/Tar.php \Drupal\Core\Archiver\Tar
  3. 8.9.x core/modules/system/src/Plugin/Archiver/Tar.php \Drupal\system\Plugin\Archiver\Tar
  4. 8.9.x core/lib/Drupal/Core/Archiver/Tar.php \Drupal\Core\Archiver\Tar
  5. 11.x core/modules/system/src/Plugin/Archiver/Tar.php \Drupal\system\Plugin\Archiver\Tar
  6. 11.x core/lib/Drupal/Core/Archiver/Tar.php \Drupal\Core\Archiver\Tar

Defines an archiver implementation for .tar files.

Hierarchy

Expanded class hierarchy of Tar

3 files declare their use of Tar
ConfigExportUITest.php in core/modules/config/tests/src/Functional/ConfigExportUITest.php
Tar.php in core/modules/system/src/Plugin/Archiver/Tar.php
TarTest.php in core/tests/Drupal/KernelTests/Core/Archiver/TarTest.php
3 string references to 'Tar'
ExtensionViewsFieldTest::testFileExtensionTarOption in core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php
Tests file extension views field handler extension_detect_tar option.
FileEntityFormatterTest::testFormatterFileExtension in core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php
Tests the file_extension field formatter.
FileExtensionFormatter::viewValue in core/modules/file/src/Plugin/Field/FieldFormatter/FileExtensionFormatter.php
Generate the output appropriate for one field item.

File

core/lib/Drupal/Core/Archiver/Tar.php, line 8

Namespace

Drupal\Core\Archiver
View source
class Tar implements ArchiverInterface {
  
  /**
   * The underlying ArchiveTar instance that does the heavy lifting.
   *
   * @var \Drupal\Core\Archiver\ArchiveTar
   */
  protected $tar;
  
  /**
   * Constructs a Tar object.
   *
   * @param string $file_path
   *   The full system path of the archive to manipulate. Only local files
   *   are supported. If the file does not yet exist, it will be created if
   *   appropriate.
   * @param array $configuration
   *   (Optional) settings to open the archive with the following keys:
   *   - 'compress': Indicates if the 'gzip', 'bz2', or 'lzma2' compression is
   *     required.
   *   - 'buffer_length': Length of the read buffer in bytes.
   *
   * @throws \Drupal\Core\Archiver\ArchiverException
   */
  public function __construct($file_path, array $configuration = []) {
    $compress = $configuration['compress'] ?? NULL;
    $buffer = $configuration['buffer_length'] ?? 512;
    $this->tar = new ArchiveTar($file_path, $compress, $buffer);
  }
  
  /**
   * {@inheritdoc}
   */
  public function add($file_path) {
    $this->tar
      ->add($file_path);
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function remove($file_path) {
    // @todo Archive_Tar doesn't have a remove operation
    // so we'll have to simulate it somehow, probably by
    // creating a new archive with everything but the removed
    // file.
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function extract($path, array $files = []) {
    if ($files) {
      $this->tar
        ->extractList($files, $path, '', FALSE, FALSE);
    }
    else {
      $this->tar
        ->extract($path, FALSE, FALSE);
    }
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function listContents() {
    $files = [];
    foreach ($this->tar
      ->listContent() as $file_data) {
      $files[] = $file_data['filename'];
    }
    return $files;
  }
  
  /**
   * Retrieves the tar engine itself.
   *
   * In some cases it may be necessary to directly access the underlying
   * ArchiveTar object for implementation-specific logic. This is for advanced
   * use only as it is not shared by other implementations of ArchiveInterface.
   *
   * @return ArchiveTar
   *   The ArchiveTar object used by this object.
   */
  public function getArchive() {
    return $this->tar;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Tar::$tar protected property The underlying ArchiveTar instance that does the heavy lifting.
Tar::add public function Adds the specified file or directory to the archive. Overrides ArchiverInterface::add
Tar::extract public function Extracts multiple files in the archive to the specified path. Overrides ArchiverInterface::extract
Tar::getArchive public function Retrieves the tar engine itself.
Tar::listContents public function Lists all files in the archive. Overrides ArchiverInterface::listContents
Tar::remove public function Removes the specified file from the archive. Overrides ArchiverInterface::remove
Tar::__construct public function Constructs a Tar object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.