Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/filesystem/archive/gzip.php

Documentation is available at gzip.php

  1. <?php
  2. /**
  3.  * @version        $Id: archive.php 6138 2007-01-02 03:44:18Z eddiea $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    FileSystem
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Gzip format adapter for the JArchive class
  20.  *
  21.  * This class is inspired from and draws heavily in code and concept from the Compress package of
  22.  * The Horde Project <http://www.horde.org>
  23.  *
  24.  * @contributor  Michael Slusarz <[email protected]>
  25.  * @contributor  Michael Cochrane <[email protected]>
  26.  *
  27.  * @author        Louis Landry <[email protected]>
  28.  * @package     Joomla.Framework
  29.  * @subpackage    FileSystem
  30.  * @since        1.5
  31.  */
  32. class JArchiveGzip extends JObject
  33. {
  34.     /**
  35.      * Gzip file flags.
  36.      * @var array 
  37.      */
  38.     var $_flags = array (
  39.         'FTEXT' => 0x01,
  40.         'FHCRC' => 0x02,
  41.         'FEXTRA' => 0x04,
  42.         'FNAME' => 0x08,
  43.         'FCOMMENT' => 0x10
  44.     );
  45.  
  46.     /**
  47.      * Gzip file data buffer
  48.      * @var string 
  49.      */
  50.     var $_data = null;
  51.  
  52.     /**
  53.     * Extract a Gzip compressed file to a given path
  54.     *
  55.     * @access    public
  56.     * @param    string    $archive        Path to ZIP archive to extract
  57.     * @param    string    $destination    Path to extract archive to
  58.     * @param    array    $options        Extraction options [unused]
  59.     * @return    boolean    True if successful
  60.     * @since    1.5
  61.     */
  62.     function extract($archive$destination$options array ())
  63.     {
  64.         // Initialize variables
  65.         $this->_data = null;
  66.  
  67.         if (!extension_loaded('zlib')) {
  68.             $this->set('error.message''Zlib Not Supported');
  69.             return JError::raiseWarning(100$this->get('error.message'));
  70.         }
  71.  
  72.         if (!$this->_data = JFile::read($archive)) {
  73.             $this->set('error.message''Unable to read archive');
  74.             return JError::raiseWarning(100$this->get('error.message'));
  75.         }
  76.  
  77.         $position $this->_getFilePosition();
  78.         $buffer gzinflate(substr($this->_data$positionstrlen($this->_data$position));
  79.         if (empty ($buffer)) {
  80.             $this->set('error.message''Unable to decompress data');
  81.             return JError::raiseWarning(100$this->get('error.message'));
  82.         }
  83.  
  84.         if (JFile::write($destination$buffer=== false{
  85.             $this->set('error.message''Unable to write archive');
  86.             return JError::raiseWarning(100$this->get('error.message'));
  87.         }
  88.         return true;
  89.     }
  90.  
  91.     /**
  92.     * Get file data offset for archive
  93.     *
  94.     * @access    public
  95.     * @return    int    Data position marker for archive
  96.     * @since    1.5
  97.     */
  98.     function _getFilePosition()
  99.     {
  100.         // gzipped file... unpack it first
  101.         $position 0;
  102.         $info unpack('CCM/CFLG/VTime/CXFL/COS'substr($this->_data$position +2));
  103.         if (!$info{
  104.             $this->set('error.message''Unable to decompress data');
  105.             return false;
  106.         }
  107.         $position += 10;
  108.  
  109.         if ($info['FLG'$this->_flags['FEXTRA']{
  110.             $XLEN unpack('vLength'substr($this->_data$position +02));
  111.             $XLEN $XLEN['Length'];
  112.             $position += $XLEN +2;
  113.         }
  114.  
  115.         if ($info['FLG'$this->_flags['FNAME']{
  116.             $filenamePos strpos($this->_data"\x0"$position);
  117.             $filename substr($this->_data$position$filenamePos $position);
  118.             $position $filenamePos +1;
  119.         }
  120.  
  121.         if ($info['FLG'$this->_flags['FCOMMENT']{
  122.             $commentPos strpos($this->_data"\x0"$position);
  123.             $comment substr($this->_data$position$commentPos $position);
  124.             $position $commentPos +1;
  125.         }
  126.  
  127.         if ($info['FLG'$this->_flags['FHCRC']{
  128.             $hcrc unpack('vCRC'substr($this->_data$position +02));
  129.             $hcrc $hcrc['CRC'];
  130.             $position += 2;
  131.         }
  132.  
  133.         return $position;
  134.     }
  135. }
  136. ?>

Documentation generated on Mon, 05 Mar 2007 21:05:14 +0000 by phpDocumentor 1.3.1