You are here

public function ArchiveTar::_openRead 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::_openRead()

Return value

bool

4 calls to ArchiveTar::_openRead()
ArchiveTar::extractInString in core/lib/Drupal/Core/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.
ArchiveTar::extractList in core/lib/Drupal/Core/Archiver/ArchiveTar.php
This method extract from the archive only the files indicated in the $p_filelist. These files are extracted in the current directory or in the directory indicated by the optional $p_path parameter. If indicated the $p_remove_path can be used in the…
ArchiveTar::extractModify in core/lib/Drupal/Core/Archiver/ArchiveTar.php
This method extract all the content of the archive in the directory indicated by $p_path. When relevant the memorized path of the files/dir can be modified by removing the $p_remove_path path at the beginning of the file/dir path. While extracting a…
ArchiveTar::listContent in core/lib/Drupal/Core/Archiver/ArchiveTar.php

File

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

Class

ArchiveTar

Namespace

Drupal\Core\Archiver

Code

public function _openRead() {
  if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {

    // ----- Look if a local copy need to be done
    if ($this->_temp_tarname == '') {
      $this->_temp_tarname = uniqid('tar') . '.tmp';
      if (!($v_file_from = @fopen($this->_tarname, 'rb'))) {
        $this
          ->_error('Unable to open in read mode \'' . $this->_tarname . '\'');
        $this->_temp_tarname = '';
        return false;
      }
      if (!($v_file_to = @fopen($this->_temp_tarname, 'wb'))) {
        $this
          ->_error('Unable to open in write mode \'' . $this->_temp_tarname . '\'');
        $this->_temp_tarname = '';
        return false;
      }
      while ($v_data = @fread($v_file_from, 1024)) {
        @fwrite($v_file_to, $v_data);
      }
      @fclose($v_file_from);
      @fclose($v_file_to);
    }

    // ----- File to open if the local copy
    $v_filename = $this->_temp_tarname;
  }
  else {

    // ----- File to open if the normal Tar file
    $v_filename = $this->_tarname;
  }
  if ($this->_compress_type == 'gz' && function_exists('gzopen')) {
    $this->_file = @gzopen($v_filename, "rb");
  }
  else {
    if ($this->_compress_type == 'bz2' && function_exists('bzopen')) {
      $this->_file = @bzopen($v_filename, "r");
    }
    else {
      if ($this->_compress_type == 'lzma2' && function_exists('xzopen')) {
        $this->_file = @xzopen($v_filename, "r");
      }
      else {
        if ($this->_compress_type == 'none') {
          $this->_file = @fopen($v_filename, "rb");
        }
        else {
          $this
            ->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
          return false;
        }
      }
    }
  }
  if ($this->_file == 0) {
    $this
      ->_error('Unable to open in read mode \'' . $v_filename . '\'');
    return false;
  }
  return true;
}