/** * Extract a ZIP compressed file to a given path * * @access public * @param string $archive Path to ZIP archive to extract * @param string $destination Path to extract archive into * @param array $options Extraction options [unused] * @return boolean True if successful * @since 1.5 */ function extract($archive, $destination, $options = array()) { // Initialize variables $this->_data = null; $this->_metadata = null; if (!($this->_data = file_get_contents($archive))) { return PEAR::raiseError('Unable to read archive'); } if (!$this->_getTarInfo($this->_data)) { return PEAR::raiseError('Unable to decompress data'); } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) { $type = strtolower($this->_metadata[$i]['type']); if ($type == 'file' || $type == 'unix file') { $buffer = $this->_metadata[$i]['data']; $path = extPath::clean($destination . DS . $this->_metadata[$i]['name']); // Make sure the destination folder exists if (!extMkdirR(dirname($path))) { return PEAR::raiseError('Unable to create destination'); } if (file_put_contents($path, $buffer) === false) { return PEAR::raiseError('Unable to write entry'); } } } return true; }
/** * Extract a ZIP compressed file to a given path using native php api calls for speed * * @access private * @param string $archive Path to ZIP archive to extract * @param string $destination Path to extract archive into * @param array $options Extraction options [unused] * @return boolean True if successful * @since 1.5 */ function _extractNative($archive, $destination, $options) { $zip = zip_open($archive); if (is_resource($zip)) { // Make sure the destination folder exists if (!is_dir($destination) && !mkdir($destination)) { return PEAR::raiseError('Unable to create destination'); } // Read files in the archive while ($file = @zip_read($zip)) { if (zip_entry_open($zip, $file, "r")) { if (substr(zip_entry_name($file), strlen(zip_entry_name($file)) - 1) != "/") { $buffer = zip_entry_read($file, zip_entry_filesize($file)); if (!extMkdirR(dirname($destination . DS . zip_entry_name($file))) || file_put_contents($destination . DS . zip_entry_name($file), $buffer) === false) { return PEAR::raiseError('Unable to write entry: ' . $destination . DS . zip_entry_name($file)); } zip_entry_close($file); } } else { return PEAR::raiseError('Unable to read entry'); } } @zip_close($zip); } else { return PEAR::raiseError("Unable to open archive: " . extArchiveZip::zipFileErrMsg($zip)); } return true; }