Changeset 1924
- Timestamp:
- 02/05/2008 10:39:20 AM (11 months ago)
- Location:
- trunk/system/libraries
- Files:
-
- 3 modified
-
Archive.php (modified) (2 diffs)
-
drivers/Archive.php (modified) (1 diff)
-
drivers/Archive/Zip.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Archive.php
r1911 r1924 49 49 * Adds files or directories, recursively, to an archive. 50 50 * 51 * @param string file or directory to add 52 * @param string|bool 51 * @param string file or directory to add 52 * @param string name to use for the given file or directory 53 * @param bool add files recursively, used with directories 53 54 * @return object 54 55 */ 55 public function add($path, $name = TRUE)56 public function add($path, $name = NULL, $recursive = NULL) 56 57 { 57 58 // Normalize to forward slashes 58 59 $path = str_replace('\\', '/', $path); 59 60 60 // Enable or disable recursion61 $recursive = ($name === TRUE) ? TRUE : FALSE;62 63 61 // Set the name 64 $name = is_string($name) ? $name :$path;62 ($name === NULL) and $name = $path; 65 63 66 64 if (file_exists($path) AND is_dir($path)) 67 65 { 66 // Force directories to end with a slash 67 $path = rtrim($path, '/').'/'; 68 $name = rtrim($name, '/').'/'; 69 70 // Add the directory to the paths 71 $this->paths[] = array($path, $name); 72 68 73 if ($recursive == TRUE) 69 74 { 70 // Force directories to end with a slash71 $path = rtrim($path, '/').'/';72 73 75 $dir = opendir($path); 74 76 while (($file = readdir($dir)) !== FALSE) … … 79 81 80 82 // Add directory contents 81 $this->add($path.$file );83 $this->add($path.$file, $name.$file, TRUE); 82 84 } 83 85 closedir($dir); -
trunk/system/libraries/drivers/Archive.php
r1911 r1924 21 21 public function create($paths, $filename = FALSE); 22 22 23 /** 24 * Add data to the archive. 25 * 26 * @param string filename 27 * @param string name of file in archive 28 * @return void 29 */ 30 public function add_data($file, $name, $contents = NULL); 31 23 32 } // End Archive_Driver Interface -
trunk/system/libraries/drivers/Archive/Zip.php
r1911 r1924 28 28 foreach ($paths as $set) 29 29 { 30 // Add each file31 $this->add_ file($set[0], $set[1]);30 // Add each path individually 31 $this->add_data($set[0], $set[1], isset($set[2]) ? $set[2] : NULL); 32 32 } 33 33 … … 77 77 } 78 78 79 /** 80 * Adds a directory to a zip. 81 * 82 * @param string path to directory 83 * @param string name of directory 84 */ 85 protected function add_dir($dir, $name) 79 public function add_data($file, $name, $contents = NULL) 86 80 { 87 // Fetch the timestamp88 $t imestamp = date::unix2dos(filemtime($dir));81 // Determine the file type: 16 = dir, 32 = file 82 $type = (substr($file, -1) === '/') ? 16 : 32; 89 83 90 $this->data[] = 91 // Start "local file header" 92 "\x50\x4b\x03\x04". // Zip header 93 "\x0a\x00". // Version required for extraction 94 "\x00\x00". // General bit flag 95 "\x00\x00". // Compression method 96 pack('V', $timestamp). // Last mod time and date 97 pack('V', crc32($name)). // CRC32 98 pack('V', 0). // Compressed filesize 99 pack('V', 0). // Uncompressed filesize 100 pack('v', strlen($name)). // Length of directory name 101 pack('v', 0). // Extra field length 102 $name; // Directory name 84 // Fetch the timestamp, using the current time if manually setting the contents 85 $timestamp = date::unix2dos(($contents === NULL) ? filemtime($file) : time()); 103 86 104 $this->dirs[] = 105 "\x50\x4b\x01\x02". // Zip header 106 "\x00\x00". // Version made by 107 "\x0a\x00". // Version required for extraction 108 "\x00\x00". // General bit flag 109 "\x00\x00". // Compression method 110 pack('V', $timestamp). // Last mod time and date 111 pack('V', crc32($name)). // CRC32 112 pack('V', 0). // Compressed filesize 113 pack('V', 0). // Uncompressed filesize 114 pack('v', strlen($name)). // Length of directory name 115 pack('v', 0). // Extra field length 116 // Data description 117 pack('v', 0). // CRC32 118 pack('v', 0). // Compressed filesize 119 pack('v', 0). // Uncompressed filesize 120 pack('V', 16). // Internal file attribute "directory" 121 pack('V', $this->offset). // Directory offset 122 $name; // Directory name 123 124 // Set the new offset 125 $this->offset = strlen(implode('', $this->data)); 126 } 127 128 /** 129 * Adds a file to a zip. 130 * 131 * @param string path to file 132 * @param string name of file 133 */ 134 protected function add_file($file, $name) 135 { 136 // Fetch the timestamp 137 $timestamp = date::unix2dos(filemtime($file)); 138 139 // Read the file 140 $data = file_get_contents($file); 87 // Read the file or use the defined contents 88 $data = ($contents === NULL) ? file_get_contents($file) : $contents; 141 89 142 90 // Gzip the data, use substr to fix a CRC bug … … 174 122 pack('v', 0). // Compressed filesize 175 123 pack('v', 0). // Uncompressed filesize 176 pack('V', 32). // External file attribute "file"124 pack('V', $type). // File attribute type 177 125 pack('V', $this->offset). // Directory offset 178 126 $name; // File name
