Source code for file /joomla/filesystem/archive/tar.php
Documentation is available at tar.php
* @version $Id: archive.php 6138 2007-01-02 03:44:18Z eddiea $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Tar format adapter for the JArchive class
* This class is inspired from and draws heavily in code and concept from the Compress package of
* The Horde Project <http://www.horde.org>
* @package Joomla.Framework
0x33 =>
'Character special file',
0x34 =>
'Block special file',
0x36 =>
'FIFO special file',
0x37 =>
'Contiguous file'
* Tar file metadata array
* Extract a ZIP compressed file to a given path
* @param string $archive Path to ZIP archive to extract
* @param string $destination Path to extract archive into
* @param array $options Extraction options [unused]
* @return boolean True if successful
function extract($archive, $destination, $options =
array ())
$this->set('error.message', 'Unable to read archive');
if (!$this->_getTarInfo($this->_data)) {
if ($this->_metadata[$i]['type'] ==
'File') {
// Make sure the destination folder exists
$this->set('error.message', 'Unable to create destination');
$this->set('error.message', 'Unable to write entry');
* Get the list of files/data from a Tar archive buffer.
* @param string $data The Tar archive buffer.
* @return array Archive metadata array
* KEY: Position in the array
* VALUES: 'attr' -- File attributes
* 'data' -- Raw file contents
* 'date' -- File modification time
* 'size' -- Original file size
function _getTarInfo(& $data)
$return_array =
array ();
while ($position <
strlen($data))
$info =
@ unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", substr($data, $position));
$this->set('error.message', 'Unable to decompress data');
$contents =
substr($data, $position, octdec($info['size']));
$position +=
ceil(octdec($info['size']) /
512) *
512;
'date' =>
octdec($info['mtime']
), 'name' =>
trim($info['filename']), 'size' =>
octdec($info['size']), 'type' => isset
($this->_types[$info['typeflag']]) ?
$this->_types[$info['typeflag']] :
null);
if (($info['typeflag'] ==
0) ||
($info['typeflag'] ==
0x30) ||
($info['typeflag'] ==
0x35)) {
$file['data'] =
$contents;
$file['attr'] =
(($info['typeflag'] ==
0x35) ?
'd' :
'-') .
(($mode & 0x400) ?
'r' :
'-') .
(($mode & 0x200) ?
'w' :
'-') .
(($mode & 0x100) ?
'x' :
'-') .
(($mode & 0x040) ?
'r' :
'-') .
(($mode & 0x020) ?
'w' :
'-') .
(($mode & 0x010) ?
'x' :
'-') .
(($mode & 0x004) ?
'r' :
'-') .
(($mode & 0x002) ?
'w' :
'-') .
(($mode & 0x001) ?
'x' :
'-');