10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.file');
35 private $_flags = array(
'FTEXT' => 0x01,
'FHCRC' => 0x02,
'FEXTRA' => 0x04,
'FNAME' => 0x08,
'FCOMMENT' => 0x10);
43 private $_data = null;
57 public function extract($archive, $destination, array $options = array ())
61 if (!extension_loaded(
'zlib'))
63 if (class_exists(
'JError'))
69 throw new RuntimeException(
'The zlib extension is not available.');
73 if (!isset($options[
'use_streams']) || $options[
'use_streams'] ==
false)
75 $this->_data = file_get_contents($archive);
79 if (class_exists(
'JError'))
85 throw new RuntimeException(
'Unable to read archive');
89 $position = $this->_getFilePosition();
90 $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position));
94 if (class_exists(
'JError'))
100 throw new RuntimeException(
'Unable to decompress data');
106 if (class_exists(
'JError'))
112 throw new RuntimeException(
'Unable to write archive');
122 $input->set(
'processingmethod',
'gz');
124 if (!$input->open($archive))
126 if (class_exists(
'JError'))
132 throw new RuntimeException(
'Unable to read archive (gz)');
138 if (!$output->open($destination,
'w'))
142 if (class_exists(
'JError'))
148 throw new RuntimeException(
'Unable to write archive (gz)');
154 $this->_data = $input->read($input->get(
'chunksize', 8196));
158 if (!$output->write($this->_data))
162 if (class_exists(
'JError'))
168 throw new RuntimeException(
'Unable to write file (gz)');
173 while ($this->_data);
188 public static function isSupported()
190 return extension_loaded(
'zlib');
201 public function _getFilePosition()
205 $info = @ unpack(
'CCM/CFLG/VTime/CXFL/COS', substr($this->_data, $position + 2));
209 if (class_exists(
'JError'))
215 throw new RuntimeException(
'Unable to decompress data.');
221 if ($info[
'FLG'] & $this->_flags[
'FEXTRA'])
223 $XLEN = unpack(
'vLength', substr($this->_data, $position + 0, 2));
224 $XLEN = $XLEN[
'Length'];
225 $position += $XLEN + 2;
228 if ($info[
'FLG'] & $this->_flags[
'FNAME'])
230 $filenamePos = strpos($this->_data,
"\x0", $position);
231 $position = $filenamePos + 1;
234 if ($info[
'FLG'] & $this->_flags[
'FCOMMENT'])
236 $commentPos = strpos($this->_data,
"\x0", $position);
237 $position = $commentPos + 1;
240 if ($info[
'FLG'] & $this->_flags[
'FHCRC'])
242 $hcrc = unpack(
'vCRC', substr($this->_data, $position + 0, 2));
243 $hcrc = $hcrc[
'CRC'];