function ArchiveTar::_extractInString

This method extract from the archive one file identified by $p_filename. The return value is a string with the file content, or NULL on error.

@access private

Parameters

string $p_filename The path of the file to extract in a string.:

Return value

a string with the file content or NULL.

1 call to ArchiveTar::_extractInString()
ArchiveTar::extractInString in drupal/core/lib/Drupal/Component/Archiver/ArchiveTar.php
This method extract from the archive one file identified by $p_filename. The return value is a string with the file content, or NULL on error.

File

drupal/core/lib/Drupal/Component/Archiver/ArchiveTar.php, line 1419

Class

ArchiveTar
Creates a (compressed) Tar archive

Namespace

Drupal\Component\Archiver

Code

function _extractInString($p_filename) {
  $v_result_str = "";
  while (strlen($v_binary_data = $this
    ->_readBlock()) != 0) {
    if (!$this
      ->_readHeader($v_binary_data, $v_header)) {
      return NULL;
    }
    if ($v_header['filename'] == '') {
      continue;
    }

    // ----- Look for long filename
    if ($v_header['typeflag'] == 'L') {
      if (!$this
        ->_readLongHeader($v_header)) {
        return NULL;
      }
    }
    if ($v_header['filename'] == $p_filename) {
      if ($v_header['typeflag'] == "5") {
        $this
          ->_error('Unable to extract in string a directory ' . 'entry {' . $v_header['filename'] . '}');
        return NULL;
      }
      else {
        $n = floor($v_header['size'] / 512);
        for ($i = 0; $i < $n; $i++) {
          $v_result_str .= $this
            ->_readBlock();
        }
        if ($v_header['size'] % 512 != 0) {
          $v_content = $this
            ->_readBlock();
          $v_result_str .= substr($v_content, 0, $v_header['size'] % 512);
        }
        return $v_result_str;
      }
    }
    else {
      $this
        ->_jumpBlock(ceil($v_header['size'] / 512));
    }
  }
  return NULL;
}