1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Horde_Compress_Gzip extends Horde_Compress_Base
17: {
18: 19:
20: public $canDecompress = true;
21:
22: 23: 24: 25: 26:
27: protected $_flags = array(
28: 'FTEXT' => 0x01,
29: 'FHCRC' => 0x02,
30: 'FEXTRA' => 0x04,
31: 'FNAME' => 0x08,
32: 'FCOMMENT' => 0x10
33: );
34:
35: 36: 37:
38: public function decompress($data, array $params = array())
39: {
40:
41: if (!Horde_Util::extensionExists('zlib')) {
42: throw new Horde_Compress_Exception(Horde_Compress_Translation::t("This server can't uncompress gzip files."));
43: }
44:
45:
46: $position = 0;
47: $info = @unpack('CCM/CFLG/VTime/CXFL/COS', substr($data, $position + 2));
48: if (!$info) {
49: throw new Horde_Compress_Exception(Horde_Compress_Translation::t("Unable to decompress data."));
50: }
51: $position += 10;
52:
53: if ($info['FLG'] & $this->_flags['FEXTRA']) {
54: $XLEN = unpack('vLength', substr($data, $position + 0, 2));
55: $XLEN = $XLEN['Length'];
56: $position += $XLEN + 2;
57: }
58:
59: if ($info['FLG'] & $this->_flags['FNAME']) {
60: $filenamePos = strpos($data, "\x0", $position);
61: $filename = substr($data, $position, $filenamePos - $position);
62: $position = $filenamePos + 1;
63: }
64:
65: if ($info['FLG'] & $this->_flags['FCOMMENT']) {
66: $commentPos = strpos($data, "\x0", $position);
67: $comment = substr($data, $position, $commentPos - $position);
68: $position = $commentPos + 1;
69: }
70:
71: if ($info['FLG'] & $this->_flags['FHCRC']) {
72: $hcrc = unpack('vCRC', substr($data, $position + 0, 2));
73: $hcrc = $hcrc['CRC'];
74: $position += 2;
75: }
76:
77: $result = @gzinflate(substr($data, $position, strlen($data) - $position));
78: if (empty($result)) {
79: throw new Horde_Compress_Exception(Horde_Compress_Translation::t("Unable to decompress data."));
80: }
81:
82: return $result;
83: }
84:
85: }
86: