10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.file');
13 jimport('joomla.filesystem.folder');
14 jimport('joomla.filesystem.path');
37 private $_types = array(
41 0x32 =>
'Symbolic link',
42 0x33 =>
'Character special file',
43 0x34 =>
'Block special file',
45 0x36 =>
'FIFO special file',
46 0x37 =>
'Contiguous file');
54 private $_data = null;
62 private $_metadata = null;
76 public function extract($archive, $destination, array $options = array())
79 $this->_metadata = null;
81 $this->_data = file_get_contents($archive);
85 if (class_exists(
'JError'))
91 throw new RuntimeException(
'Unable to read archive');
95 $this->_getTarInfo($this->_data);
97 for ($i = 0, $n = count($this->_metadata); $i < $n; $i++)
99 $type = strtolower($this->_metadata[$i][
'type']);
101 if ($type ==
'file' || $type ==
'unix file')
103 $buffer = $this->_metadata[$i][
'data'];
104 $path =
JPath::clean($destination .
'/' . $this->_metadata[$i][
'name']);
109 if (class_exists(
'JError'))
115 throw new RuntimeException(
'Unable to create destination');
120 if (class_exists(
'JError'))
126 throw new RuntimeException(
'Unable to write entry');
141 public static function isSupported()
164 protected function _getTarInfo(& $data)
167 $return_array = array();
169 while ($position < strlen($data))
172 "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor",
173 substr($data, $position)
178 if (class_exists(
'JError'))
184 throw new RuntimeException(
'Unable to decompress data');
189 $contents = substr($data, $position, octdec($info[
'size']));
190 $position += ceil(octdec($info[
'size']) / 512) * 512;
192 if ($info[
'filename'])
197 'date' => octdec($info[
'mtime']),
198 'name' => trim($info[
'filename']),
199 'size' => octdec($info[
'size']),
200 'type' => isset($this->_types[$info[
'typeflag']]) ? $this->_types[$info[
'typeflag']] : null);
202 if (($info[
'typeflag'] == 0) || ($info[
'typeflag'] == 0x30) || ($info[
'typeflag'] == 0x35))
205 $file[
'data'] = $contents;
207 $mode = hexdec(substr($info[
'mode'], 4, 3));
208 $file[
'attr'] = (($info[
'typeflag'] == 0x35) ?
'd' :
'-') . (($mode & 0x400) ?
'r' :
'-') . (($mode & 0x200) ?
'w' :
'-') .
209 (($mode & 0x100) ?
'x' :
'-') . (($mode & 0x040) ?
'r' :
'-') . (($mode & 0x020) ?
'w' :
'-') . (($mode & 0x010) ?
'x' :
'-') .
210 (($mode & 0x004) ?
'r' :
'-') . (($mode & 0x002) ?
'w' :
'-') . (($mode & 0x001) ?
'x' :
'-');
216 $return_array[] = $file;
219 $this->_metadata = $return_array;