You are here

public function ArchiveTar::_addString in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Archiver/ArchiveTar.php \Drupal\Core\Archiver\ArchiveTar::_addString()

Parameters

string $p_filename:

string $p_string:

bool $p_datetime:

array $p_params:

Return value

bool

1 call to ArchiveTar::_addString()
ArchiveTar::addString in core/lib/Drupal/Core/Archiver/ArchiveTar.php
This method add a single string as a file at the end of the existing archive. If the archive does not yet exists it is created.

File

core/lib/Drupal/Core/Archiver/ArchiveTar.php, line 1337

Class

ArchiveTar

Namespace

Drupal\Core\Archiver

Code

public function _addString($p_filename, $p_string, $p_datetime = false, $p_params = array()) {
  $p_stamp = @$p_params["stamp"] ? $p_params["stamp"] : ($p_datetime ? $p_datetime : time());
  $p_mode = @$p_params["mode"] ? $p_params["mode"] : 0600;
  $p_type = @$p_params["type"] ? $p_params["type"] : "";
  $p_uid = @$p_params["uid"] ? $p_params["uid"] : 0;
  $p_gid = @$p_params["gid"] ? $p_params["gid"] : 0;
  if (!$this->_file) {
    $this
      ->_error('Invalid file descriptor');
    return false;
  }
  if ($p_filename == '') {
    $this
      ->_error('Invalid file name');
    return false;
  }

  // ----- Calculate the stored filename
  $p_filename = $this
    ->_translateWinPath($p_filename, false);

  // ----- If datetime is not specified, set current time
  if ($p_datetime === false) {
    $p_datetime = time();
  }
  if (!$this
    ->_writeHeaderBlock($p_filename, strlen($p_string), $p_stamp, $p_mode, $p_type, $p_uid, $p_gid)) {
    return false;
  }
  $i = 0;
  while (($v_buffer = substr($p_string, $i++ * 512, 512)) != '') {
    $v_binary_data = pack("a512", $v_buffer);
    $this
      ->_writeBlock($v_binary_data);
  }
  return true;
}