[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Compress_tar class allows tar files to be read. 4 * 5 * $Horde: framework/Compress/Compress/tar.php,v 1.4.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_tar extends Horde_Compress { 19 20 /** 21 * Tar file types. 22 * 23 * @var array 24 */ 25 var $_types = array( 26 0x0 => 'Unix file', 27 0x30 => 'File', 28 0x31 => 'Link', 29 0x32 => 'Symbolic link', 30 0x33 => 'Character special file', 31 0x34 => 'Block special file', 32 0x35 => 'Directory', 33 0x36 => 'FIFO special file', 34 0x37 => 'Contiguous file' 35 ); 36 37 /** 38 * Tar file flags. 39 * 40 * @var array 41 */ 42 var $_flags = array( 43 'FTEXT' => 0x01, 44 'FHCRC' => 0x02, 45 'FEXTRA' => 0x04, 46 'FNAME' => 0x08, 47 'FCOMMENT' => 0x10 48 ); 49 50 /** 51 * Decompress a tar file and get information from it. 52 * 53 * @param string &$data The tar file data. 54 * @param array $params The parameter array (Unused). 55 * 56 * @return array The requested data or PEAR_Error on error. 57 * <pre> 58 * KEY: Position in the array 59 * VALUES: 'attr' -- File attributes 60 * 'data' -- Raw file contents 61 * 'date' -- File modification time 62 * 'name' -- Filename 63 * 'size' -- Original file size 64 * 'type' -- File type 65 * </pre> 66 */ 67 function decompress(&$data, $params = array()) 68 { 69 $position = 0; 70 $return_array = array(); 71 72 while ($position < strlen($data)) { 73 $info = @unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", substr($data, $position)); 74 if (!$info) { 75 return PEAR::raiseError(_("Unable to decompress data.")); 76 } 77 78 $position += 512; 79 $contents = substr($data, $position, octdec($info['size'])); 80 $position += ceil(octdec($info['size']) / 512) * 512; 81 82 if ($info['filename']) { 83 $file = array( 84 'attr' => null, 85 'data' => null, 86 'date' => octdec($info['mtime']), 87 'name' => trim($info['filename']), 88 'size' => octdec($info['size']), 89 'type' => isset($this->_types[$info['typeflag']]) ? $this->_types[$info['typeflag']] : null 90 ); 91 92 if (($info['typeflag'] == 0) || 93 ($info['typeflag'] == 0x30) || 94 ($info['typeflag'] == 0x35)) { 95 /* File or folder. */ 96 $file['data'] = $contents; 97 98 $mode = hexdec(substr($info['mode'], 4, 3)); 99 $file['attr'] = 100 (($info['typeflag'] == 0x35) ? 'd' : '-') . 101 (($mode & 0x400) ? 'r' : '-') . 102 (($mode & 0x200) ? 'w' : '-') . 103 (($mode & 0x100) ? 'x' : '-') . 104 (($mode & 0x040) ? 'r' : '-') . 105 (($mode & 0x020) ? 'w' : '-') . 106 (($mode & 0x010) ? 'x' : '-') . 107 (($mode & 0x004) ? 'r' : '-') . 108 (($mode & 0x002) ? 'w' : '-') . 109 (($mode & 0x001) ? 'x' : '-'); 110 } else { 111 /* Some other type. */ 112 } 113 114 $return_array[] = $file; 115 } 116 } 117 118 return $return_array; 119 } 120 121 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |