You are here

function PclZip::privExtractFileUsingTempFile in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php \PclZip::privExtractFileUsingTempFile()
1 call to PclZip::privExtractFileUsingTempFile()
PclZip::privExtractFile in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php, line 3966

Class

PclZip

Code

function privExtractFileUsingTempFile(&$p_entry, &$p_options) {
  $v_result = 1;

  // ----- Creates a temporary file
  $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.gz';
  if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
    fclose($v_file);
    PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary write mode');
    return PclZip::errorCode();
  }

  // ----- Write gz file format header
  $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x0), time(), Chr(0x0), Chr(3));
  @fwrite($v_dest_file, $v_binary_data, 10);

  // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
  $v_size = $p_entry['compressed_size'];
  while ($v_size != 0) {
    $v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
    $v_buffer = @fread($this->zip_fd, $v_read_size);

    //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
    @fwrite($v_dest_file, $v_buffer, $v_read_size);
    $v_size -= $v_read_size;
  }

  // ----- Write gz file format footer
  $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
  @fwrite($v_dest_file, $v_binary_data, 8);

  // ----- Close the temporary file
  @fclose($v_dest_file);

  // ----- Opening destination file
  if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
    $p_entry['status'] = "write_error";
    return $v_result;
  }

  // ----- Open the temporary gz file
  if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
    @fclose($v_dest_file);
    $p_entry['status'] = "read_error";
    PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode');
    return PclZip::errorCode();
  }

  // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
  $v_size = $p_entry['size'];
  while ($v_size != 0) {
    $v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
    $v_buffer = @gzread($v_src_file, $v_read_size);

    //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
    @fwrite($v_dest_file, $v_buffer, $v_read_size);
    $v_size -= $v_read_size;
  }
  @fclose($v_dest_file);
  @gzclose($v_src_file);

  // ----- Delete the temporary file
  @unlink($v_gzip_temp_name);

  // ----- Return
  return $v_result;
}