Archive_Tar::_addString PHP Method

_addString() public method

{{{ _addString()
public _addString ( $p_filename, $p_string )
    function _addString($p_filename, $p_string)
    {
        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 (!$this->_writeHeaderBlock($p_filename, strlen($p_string), time(), 384, "", 0, 0)) {
            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;
    }

Usage Example

示例#1
0
 /** Generate a tar/tgz/bz file
  * If you define $installer, this function will also put in
  * the archive a file (si)
  *
  * @param unknown_type $file
  * @param unknown_type $format 
  * @param bool $installer filename for an instaler file
  */
 function generateTarGz($file, $format = 'gz', $installer = null)
 {
     if (!class_exists('Archive_Tar')) {
         include $this->dataDir . '/archive_tar.php';
     }
     $cp = new Archive_Tar($file, $format);
     $v_result = true;
     if (!$cp->_openWrite()) {
         return false;
     }
     foreach ($this->vfsFiles as $n => $v) {
         if (!$cp->_addString(substr($n, 1), $v)) {
             return false;
         }
     }
     $cp->_writeFooter();
     $cp->_close();
     return true;
 }