1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Horde_Compress_Tar extends Horde_Compress_Base
17: {
18: 19:
20: public $canDecompress = true;
21:
22: 23: 24: 25: 26:
27: protected $_types = array(
28: 0x0 => 'Unix file',
29: 0x30 => 'File',
30: 0x31 => 'Link',
31: 0x32 => 'Symbolic link',
32: 0x33 => 'Character special file',
33: 0x34 => 'Block special file',
34: 0x35 => 'Directory',
35: 0x36 => 'FIFO special file',
36: 0x37 => 'Contiguous file'
37: );
38:
39: 40: 41: 42: 43:
44: protected $_flags = array(
45: 'FTEXT' => 0x01,
46: 'FHCRC' => 0x02,
47: 'FEXTRA' => 0x04,
48: 'FNAME' => 0x08,
49: 'FCOMMENT' => 0x10
50: );
51:
52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
67: public function decompress($data, array $params = array())
68: {
69: $data_len = strlen($data);
70: $position = 0;
71: $return_array = array();
72:
73: while ($position < $data_len) {
74: $info = @unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", substr($data, $position));
75: if (!$info) {
76: throw new Horde_Compress_Exception(Horde_Compress_Translation::t("Unable to decompress data."));
77: }
78:
79: $position += 512;
80: $contents = substr($data, $position, octdec($info['size']));
81: $position += ceil(octdec($info['size']) / 512) * 512;
82:
83: if ($info['filename']) {
84: $file = array(
85: 'attr' => null,
86: 'data' => null,
87: 'date' => octdec($info['mtime']),
88: 'name' => trim($info['filename']),
89: 'size' => octdec($info['size']),
90: 'type' => isset($this->_types[$info['typeflag']]) ? $this->_types[$info['typeflag']] : null
91: );
92:
93: if (($info['typeflag'] == 0) ||
94: ($info['typeflag'] == 0x30) ||
95: ($info['typeflag'] == 0x35)) {
96:
97: $file['data'] = $contents;
98:
99: $mode = hexdec(substr($info['mode'], 4, 3));
100: $file['attr'] =
101: (($info['typeflag'] == 0x35) ? 'd' : '-') .
102: (($mode & 0x400) ? 'r' : '-') .
103: (($mode & 0x200) ? 'w' : '-') .
104: (($mode & 0x100) ? 'x' : '-') .
105: (($mode & 0x040) ? 'r' : '-') .
106: (($mode & 0x020) ? 'w' : '-') .
107: (($mode & 0x010) ? 'x' : '-') .
108: (($mode & 0x004) ? 'r' : '-') .
109: (($mode & 0x002) ? 'w' : '-') .
110: (($mode & 0x001) ? 'x' : '-');
111: }
112:
113: $return_array[] = $file;
114: }
115: }
116:
117: return $return_array;
118: }
119:
120: }
121: