API16

JArchiveGzip/extract

From Joomla! Documentation

< API16:JArchiveGzip
Revision as of 17:47, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Extract a Gzip compressed file to a given path <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JArchiveGzip/extract|Edit Descripton...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Extract a Gzip compressed file to a given path

[Edit Descripton]

Template:Description:JArchiveGzip/extract

Syntax[edit]

extract($archive, $destination, $options=array())
Parameter Name Default Value Description
$archive $archive Path to ZIP archive to extract
$destination $destination Path to extract archive to
$options array() $options Extraction options [unused]

Returns[edit]

boolean True if successful

Defined in[edit]

libraries/joomla/filesystem/archive/gzip.php

Importing[edit]

jimport( 'joomla.filesystem.archive.gzip' );

Source Body[edit]

function extract($archive, $destination, $options = array ())
{
        // Initialise variables.
        $this->_data = null;

        if (!extension_loaded('zlib')) {
                $this->set('error.message', 'Zlib Not Supported');
                return JError::raiseWarning(100, $this->get('error.message'));
        }

        /*
        if (!$this->_data = JFile::read($archive)) {
                $this->set('error.message', 'Unable to read archive');
                return JError::raiseWarning(100, $this->get('error.message'));
        }

        $position = $this->_getFilePosition();
        $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position));
        if (empty ($buffer)) {
                $this->set('error.message', 'Unable to decompress data');
                return JError::raiseWarning(100, $this->get('error.message'));
        }

        if (JFile::write($destination, $buffer) === false) {
                $this->set('error.message', 'Unable to write archive');
                return JError::raiseWarning(100, $this->get('error.message'));
        }
        return true;
        */
        // New style! streams!
        $input =& JFactory::getStream();
        $input->set('processingmethod','gz'); // use gz
        if(!$input->open($archive)) {
                $this->set('error.message', 'Unable to read archive (gz)');
                return JError::raiseWarning(100, $this->get('error.message'));
        }

        $output =& JFactory::getStream();
        if(!$output->open($destination, 'w')) {
                $this->set('error.message', 'Unable to write archive (gz)');
                $input->close(); // close the previous file
                return JError::raiseWarning(100, $this->get('error.message'));
        }

        $written = 0;
        do {
                $this->_data = $input->read($input->get('chunksize', 8196));
                if($this->_data) {
                        if(!$output->write($this->_data)) {
                                $this->set('error.message', 'Unable to write file (gz)');
                                return JError::raiseWarning(100, $this->get('error.message'));
                        }
                }
        } while ($this->_data);
        $output->close();
        $input->close();
        return true;
}

[Edit See Also] Template:SeeAlso:JArchiveGzip/extract

Examples[edit]

<CodeExamplesForm />