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/bzip2.php

Documentation is available at bzip2.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.  * Bzip2 format adapter for the JArchive class
  20.  *
  21.  * @author        Louis Landry <[email protected]>
  22.  * @package     Joomla.Framework
  23.  * @subpackage    FileSystem
  24.  * @since        1.5
  25.  */
  26. class JArchiveBzip2 extends JObject
  27. {
  28.     /**
  29.      * Bzip2 file data buffer
  30.      * @var string 
  31.      */
  32.     var $_data = null;
  33.  
  34.     /**
  35.      * Constructor tries to load the bz2 extension of not loaded
  36.      *
  37.      * @access    protected
  38.      * @return    void 
  39.      * @since    1.5
  40.      */
  41.     function __construct()
  42.     {
  43.         // Is bz2 extension loaded?  If not try to load it
  44.         if (!extension_loaded('bz2')) {
  45.             if (JPATH_ISWIN{
  46.                 dl('php_bz2.dll');
  47.             else {
  48.                 dl('bz2.so');
  49.             }
  50.         }
  51.     }
  52.  
  53.     /**
  54.     * Extract a Bzip2 compressed file to a given path
  55.     *
  56.     * @access    public
  57.     * @param    string    $archive        Path to Bzip2 archive to extract
  58.     * @param    string    $destination    Path to extract archive to
  59.     * @param    array    $options        Extraction options [unused]
  60.     * @return    boolean    True if successful
  61.     * @since    1.5
  62.     */
  63.     function extract($archive$destination$options array ())
  64.     {
  65.         // Initialize variables
  66.         $this->_data = null;
  67.  
  68.         if (!extension_loaded('bz2')) {
  69.             $this->set('error.message''BZip2 Not Supported');
  70.             return JError::raiseWarning(100$this->get('error.message'));
  71.         }
  72.  
  73.         if (!$this->_data = JFile::read($archive)) {
  74.             $this->set('error.message''Unable to read archive');
  75.             return JError::raiseWarning(100$this->get('error.message'));
  76.         }
  77.  
  78.         $buffer bzdecompress($this->_data);
  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. ?>

Documentation generated on Mon, 05 Mar 2007 20:53:35 +0000 by phpDocumentor 1.3.1