[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Compress/ -> gzip.php (source)

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


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7