1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?php
/**
* The Horde_Compress_gzip class allows gzip files to be read.
*
* $Horde: framework/Compress/Compress/gzip.php,v 1.7.12.9 2006/04/30 22:28:29 chuck Exp $
*
* Copyright 2002-2006 Michael Cochrane <mike@graftonhall.co.nz>
* Copyright 2003-2006 Michael Slusarz <slusarz@bigworm.colorado.edu>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Michael Cochrane <mike@graftonhall.co.nz>
* @author Michael Slusarz <slusarz@bigworm.colorado.edu>
* @since Horde 3.0
* @package Horde_Compress
*/
class Horde_Compress_gzip extends Horde_Compress {
/**
* Gzip file flags.
*
* @var array
*/
var $_flags = array(
'FTEXT' => 0x01,
'FHCRC' => 0x02,
'FEXTRA' => 0x04,
'FNAME' => 0x08,
'FCOMMENT' => 0x10
);
/**
* Decompress a gzip file and get information from it.
*
* @param string &$data The tar file data.
* @param array $params The parameter array (Unused).
*
* @return string The uncompressed data.
*/
function decompress(&$data, $params = array())
{
/* If gzip is not compiled into PHP, return now. */
if (!Util::extensionExists('zlib')) {
return PEAR::raiseError(_("This server can't uncompress zip and gzip files."));
}
/* Gzipped File - decompress it first. */
$position = 0;
$info = @unpack('CCM/CFLG/VTime/CXFL/COS', substr($data, $position + 2));
if (!$info) {
return PEAR::raiseError(_("Unable to decompress data."));
}
$position += 10;
if ($info['FLG'] & $this->_flags['FEXTRA']) {
$XLEN = unpack('vLength', substr($data, $position + 0, 2));
$XLEN = $XLEN['Length'];
$position += $XLEN + 2;
}
if ($info['FLG'] & $this->_flags['FNAME']) {
$filenamePos = strpos($data, "\x0", $position);
$filename = substr($data, $position, $filenamePos - $position);
$position = $filenamePos + 1;
}
if ($info['FLG'] & $this->_flags['FCOMMENT']) {
$commentPos = strpos($data, "\x0", $position);
$comment = substr($data, $position, $commentPos - $position);
$position = $commentPos + 1;
}
if ($info['FLG'] & $this->_flags['FHCRC']) {
$hcrc = unpack('vCRC', substr($data, $position + 0, 2));
$hcrc = $hcrc['CRC'];
$position += 2;
}
$result = @gzinflate(substr($data, $position, strlen($data) - $position));
if (empty($result)) {
return PEAR::raiseError(_("Unable to decompress data."));
}
return $result;
}
}
|