Chris@18
|
1 Documentation for class Archive_Tar
|
Chris@18
|
2 ===================================
|
Chris@18
|
3 Last update : 2001-08-15
|
Chris@18
|
4
|
Chris@18
|
5
|
Chris@18
|
6
|
Chris@18
|
7 Overview :
|
Chris@18
|
8 ----------
|
Chris@18
|
9
|
Chris@18
|
10 The Archive_Tar class helps in creating and managing GNU TAR format
|
Chris@18
|
11 files compressed by GNU ZIP or not.
|
Chris@18
|
12 The class offers basic functions like creating an archive, adding
|
Chris@18
|
13 files in the archive, extracting files from the archive and listing
|
Chris@18
|
14 the archive content.
|
Chris@18
|
15 It also provide advanced functions that allow the adding and
|
Chris@18
|
16 extraction of files with path manipulation.
|
Chris@18
|
17
|
Chris@18
|
18
|
Chris@18
|
19 Sample :
|
Chris@18
|
20 --------
|
Chris@18
|
21
|
Chris@18
|
22 // ----- Creating the object (uncompressed archive)
|
Chris@18
|
23 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
24 $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
|
Chris@18
|
25
|
Chris@18
|
26 // ----- Creating the archive
|
Chris@18
|
27 $v_list[0]="file.txt";
|
Chris@18
|
28 $v_list[1]="data/";
|
Chris@18
|
29 $v_list[2]="file.log";
|
Chris@18
|
30 $tar_object->create($v_list);
|
Chris@18
|
31
|
Chris@18
|
32 // ----- Adding files
|
Chris@18
|
33 $v_list[0]="dev/file.txt";
|
Chris@18
|
34 $v_list[1]="dev/data/";
|
Chris@18
|
35 $v_list[2]="log/file.log";
|
Chris@18
|
36 $tar_object->add($v_list);
|
Chris@18
|
37
|
Chris@18
|
38 // ----- Adding more files
|
Chris@18
|
39 $tar_object->add("release/newfile.log release/readme.txt");
|
Chris@18
|
40
|
Chris@18
|
41 // ----- Listing the content
|
Chris@18
|
42 if (($v_list = $tar_object->listContent()) != 0)
|
Chris@18
|
43 for ($i=0; $i<sizeof($v_list); $i++)
|
Chris@18
|
44 {
|
Chris@18
|
45 echo "Filename :'".$v_list[$i][filename]."'<br>";
|
Chris@18
|
46 echo " .size :'".$v_list[$i][size]."'<br>";
|
Chris@18
|
47 echo " .mtime :'".$v_list[$i][mtime]."' (".date("l dS of F Y h:i:s A", $v_list[$i][mtime]).")<br>";
|
Chris@18
|
48 echo " .mode :'".$v_list[$i][mode]."'<br>";
|
Chris@18
|
49 echo " .uid :'".$v_list[$i][uid]."'<br>";
|
Chris@18
|
50 echo " .gid :'".$v_list[$i][gid]."'<br>";
|
Chris@18
|
51 echo " .typeflag :'".$v_list[$i][typeflag]."'<br>";
|
Chris@18
|
52 }
|
Chris@18
|
53
|
Chris@18
|
54 // ----- Extracting the archive in directory "install"
|
Chris@18
|
55 $tar_object->extract("install");
|
Chris@18
|
56
|
Chris@18
|
57
|
Chris@18
|
58 Public arguments :
|
Chris@18
|
59 ------------------
|
Chris@18
|
60
|
Chris@18
|
61 None
|
Chris@18
|
62
|
Chris@18
|
63
|
Chris@18
|
64 Public Methods :
|
Chris@18
|
65 ----------------
|
Chris@18
|
66
|
Chris@18
|
67 Method : Archive_Tar($p_tarname, $compress = null)
|
Chris@18
|
68 Description :
|
Chris@18
|
69 Archive_Tar Class constructor. This flavour of the constructor only
|
Chris@18
|
70 declare a new Archive_Tar object, identifying it by the name of the
|
Chris@18
|
71 tar file.
|
Chris@18
|
72 If the compress argument is set the tar will be read or created as a
|
Chris@18
|
73 gzip or bz2 compressed TAR file.
|
Chris@18
|
74 Arguments :
|
Chris@18
|
75 $p_tarname : A valid filename for the tar archive file.
|
Chris@18
|
76 $p_compress : can be null, 'gz' or 'bz2'. For
|
Chris@18
|
77 compatibility reason it can also be true. This
|
Chris@18
|
78 parameter indicates if gzip or bz2 compression
|
Chris@18
|
79 is required.
|
Chris@18
|
80 Return value :
|
Chris@18
|
81 The Archive_Tar object.
|
Chris@18
|
82 Sample :
|
Chris@18
|
83 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
84 $tar_object_compressed = new Archive_Tar("tarname.tgz", true);
|
Chris@18
|
85 How it works :
|
Chris@18
|
86 Initialize the object.
|
Chris@18
|
87
|
Chris@18
|
88 Method : create($p_filelist)
|
Chris@18
|
89 Description :
|
Chris@18
|
90 This method creates the archive file and add the files / directories
|
Chris@18
|
91 that are listed in $p_filelist.
|
Chris@18
|
92 If the file already exists and is writable, it is replaced by the
|
Chris@18
|
93 new tar. It is a create and not an add. If the file exists and is
|
Chris@18
|
94 read-only or is a directory it is not replaced. The method return
|
Chris@18
|
95 false and a PEAR error text.
|
Chris@18
|
96 The $p_filelist parameter can be an array of string, each string
|
Chris@18
|
97 representing a filename or a directory name with their path if
|
Chris@18
|
98 needed. It can also be a single string with names separated by a
|
Chris@18
|
99 single blank.
|
Chris@18
|
100 See also createModify() method for more details.
|
Chris@18
|
101 Arguments :
|
Chris@18
|
102 $p_filelist : An array of filenames and directory names, or a single
|
Chris@18
|
103 string with names separated by a single blank space.
|
Chris@18
|
104 Return value :
|
Chris@18
|
105 true on success, false on error.
|
Chris@18
|
106 Sample 1 :
|
Chris@18
|
107 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
108 $tar_object->setErrorHandling(PEAR_ERROR_PRINT); // Optional error handling
|
Chris@18
|
109 $v_list[0]="file.txt";
|
Chris@18
|
110 $v_list[1]="data/"; (Optional '/' at the end)
|
Chris@18
|
111 $v_list[2]="file.log";
|
Chris@18
|
112 $tar_object->create($v_list);
|
Chris@18
|
113 Sample 2 :
|
Chris@18
|
114 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
115 $tar_object->setErrorHandling(PEAR_ERROR_PRINT); // Optional error handling
|
Chris@18
|
116 $tar_object->create("file.txt data/ file.log");
|
Chris@18
|
117 How it works :
|
Chris@18
|
118 Just calling the createModify() method with the right parameters.
|
Chris@18
|
119
|
Chris@18
|
120 Method : createModify($p_filelist, $p_add_dir, $p_remove_dir = "")
|
Chris@18
|
121 Description :
|
Chris@18
|
122 This method creates the archive file and add the files / directories
|
Chris@18
|
123 that are listed in $p_filelist.
|
Chris@18
|
124 If the file already exists and is writable, it is replaced by the
|
Chris@18
|
125 new tar. It is a create and not an add. If the file exists and is
|
Chris@18
|
126 read-only or is a directory it is not replaced. The method return
|
Chris@18
|
127 false and a PEAR error text.
|
Chris@18
|
128 The $p_filelist parameter can be an array of string, each string
|
Chris@18
|
129 representing a filename or a directory name with their path if
|
Chris@18
|
130 needed. It can also be a single string with names separated by a
|
Chris@18
|
131 single blank.
|
Chris@18
|
132 The path indicated in $p_remove_dir will be removed from the
|
Chris@18
|
133 memorized path of each file / directory listed when this path
|
Chris@18
|
134 exists. By default nothing is removed (empty path "")
|
Chris@18
|
135 The path indicated in $p_add_dir will be added at the beginning of
|
Chris@18
|
136 the memorized path of each file / directory listed. However it can
|
Chris@18
|
137 be set to empty "". The adding of a path is done after the removing
|
Chris@18
|
138 of path.
|
Chris@18
|
139 The path add/remove ability enables the user to prepare an archive
|
Chris@18
|
140 for extraction in a different path than the origin files are.
|
Chris@18
|
141 See also addModify() method for file adding properties.
|
Chris@18
|
142 Arguments :
|
Chris@18
|
143 $p_filelist : An array of filenames and directory names, or a single
|
Chris@18
|
144 string with names separated by a single blank space.
|
Chris@18
|
145 $p_add_dir : A string which contains a path to be added to the
|
Chris@18
|
146 memorized path of each element in the list.
|
Chris@18
|
147 $p_remove_dir : A string which contains a path to be removed from
|
Chris@18
|
148 the memorized path of each element in the list, when
|
Chris@18
|
149 relevant.
|
Chris@18
|
150 Return value :
|
Chris@18
|
151 true on success, false on error.
|
Chris@18
|
152 Sample 1 :
|
Chris@18
|
153 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
154 $tar_object->setErrorHandling(PEAR_ERROR_PRINT); // Optional error handling
|
Chris@18
|
155 $v_list[0]="file.txt";
|
Chris@18
|
156 $v_list[1]="data/"; (Optional '/' at the end)
|
Chris@18
|
157 $v_list[2]="file.log";
|
Chris@18
|
158 $tar_object->createModify($v_list, "install");
|
Chris@18
|
159 // files are stored in the archive as :
|
Chris@18
|
160 // install/file.txt
|
Chris@18
|
161 // install/data
|
Chris@18
|
162 // install/data/file1.txt
|
Chris@18
|
163 // install/data/... all the files and sub-dirs of data/
|
Chris@18
|
164 // install/file.log
|
Chris@18
|
165 Sample 2 :
|
Chris@18
|
166 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
167 $tar_object->setErrorHandling(PEAR_ERROR_PRINT); // Optional error handling
|
Chris@18
|
168 $v_list[0]="dev/file.txt";
|
Chris@18
|
169 $v_list[1]="dev/data/"; (Optional '/' at the end)
|
Chris@18
|
170 $v_list[2]="log/file.log";
|
Chris@18
|
171 $tar_object->createModify($v_list, "install", "dev");
|
Chris@18
|
172 // files are stored in the archive as :
|
Chris@18
|
173 // install/file.txt
|
Chris@18
|
174 // install/data
|
Chris@18
|
175 // install/data/file1.txt
|
Chris@18
|
176 // install/data/... all the files and sub-dirs of data/
|
Chris@18
|
177 // install/log/file.log
|
Chris@18
|
178 How it works :
|
Chris@18
|
179 Open the file in write mode (erasing the existing one if one),
|
Chris@18
|
180 call the _addList() method for adding the files in an empty archive,
|
Chris@18
|
181 add the tar footer (512 bytes block), close the tar file.
|
Chris@18
|
182
|
Chris@18
|
183
|
Chris@18
|
184 Method : addModify($p_filelist, $p_add_dir, $p_remove_dir="")
|
Chris@18
|
185 Description :
|
Chris@18
|
186 This method add the files / directories listed in $p_filelist at the
|
Chris@18
|
187 end of the existing archive. If the archive does not yet exists it
|
Chris@18
|
188 is created.
|
Chris@18
|
189 The $p_filelist parameter can be an array of string, each string
|
Chris@18
|
190 representing a filename or a directory name with their path if
|
Chris@18
|
191 needed. It can also be a single string with names separated by a
|
Chris@18
|
192 single blank.
|
Chris@18
|
193 The path indicated in $p_remove_dir will be removed from the
|
Chris@18
|
194 memorized path of each file / directory listed when this path
|
Chris@18
|
195 exists. By default nothing is removed (empty path "")
|
Chris@18
|
196 The path indicated in $p_add_dir will be added at the beginning of
|
Chris@18
|
197 the memorized path of each file / directory listed. However it can
|
Chris@18
|
198 be set to empty "". The adding of a path is done after the removing
|
Chris@18
|
199 of path.
|
Chris@18
|
200 The path add/remove ability enables the user to prepare an archive
|
Chris@18
|
201 for extraction in a different path than the origin files are.
|
Chris@18
|
202 If a file/dir is already in the archive it will only be added at the
|
Chris@18
|
203 end of the archive. There is no update of the existing archived
|
Chris@18
|
204 file/dir. However while extracting the archive, the last file will
|
Chris@18
|
205 replace the first one. This results in a none optimization of the
|
Chris@18
|
206 archive size.
|
Chris@18
|
207 If a file/dir does not exist the file/dir is ignored. However an
|
Chris@18
|
208 error text is send to PEAR error.
|
Chris@18
|
209 If a file/dir is not readable the file/dir is ignored. However an
|
Chris@18
|
210 error text is send to PEAR error.
|
Chris@18
|
211 If the resulting filename/dirname (after the add/remove option or
|
Chris@18
|
212 not) string is greater than 99 char, the file/dir is
|
Chris@18
|
213 ignored. However an error text is send to PEAR error.
|
Chris@18
|
214 Arguments :
|
Chris@18
|
215 $p_filelist : An array of filenames and directory names, or a single
|
Chris@18
|
216 string with names separated by a single blank space.
|
Chris@18
|
217 $p_add_dir : A string which contains a path to be added to the
|
Chris@18
|
218 memorized path of each element in the list.
|
Chris@18
|
219 $p_remove_dir : A string which contains a path to be removed from
|
Chris@18
|
220 the memorized path of each element in the list, when
|
Chris@18
|
221 relevant.
|
Chris@18
|
222 Return value :
|
Chris@18
|
223 true on success, false on error.
|
Chris@18
|
224 Sample 1 :
|
Chris@18
|
225 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
226 [...]
|
Chris@18
|
227 $v_list[0]="dev/file.txt";
|
Chris@18
|
228 $v_list[1]="dev/data/"; (Optional '/' at the end)
|
Chris@18
|
229 $v_list[2]="log/file.log";
|
Chris@18
|
230 $tar_object->addModify($v_list, "install");
|
Chris@18
|
231 // files are stored in the archive as :
|
Chris@18
|
232 // install/file.txt
|
Chris@18
|
233 // install/data
|
Chris@18
|
234 // install/data/file1.txt
|
Chris@18
|
235 // install/data/... all the files and sub-dirs of data/
|
Chris@18
|
236 // install/file.log
|
Chris@18
|
237 Sample 2 :
|
Chris@18
|
238 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
239 [...]
|
Chris@18
|
240 $v_list[0]="dev/file.txt";
|
Chris@18
|
241 $v_list[1]="dev/data/"; (Optional '/' at the end)
|
Chris@18
|
242 $v_list[2]="log/file.log";
|
Chris@18
|
243 $tar_object->addModify($v_list, "install", "dev");
|
Chris@18
|
244 // files are stored in the archive as :
|
Chris@18
|
245 // install/file.txt
|
Chris@18
|
246 // install/data
|
Chris@18
|
247 // install/data/file1.txt
|
Chris@18
|
248 // install/data/... all the files and sub-dirs of data/
|
Chris@18
|
249 // install/log/file.log
|
Chris@18
|
250 How it works :
|
Chris@18
|
251 If the archive does not exists it create it and add the files.
|
Chris@18
|
252 If the archive does exists and is not compressed, it open it, jump
|
Chris@18
|
253 before the last empty 512 bytes block (tar footer) and add the files
|
Chris@18
|
254 at this point.
|
Chris@18
|
255 If the archive does exists and is compressed, a temporary copy file
|
Chris@18
|
256 is created. This temporary file is then 'gzip' read block by block
|
Chris@18
|
257 until the last empty block. The new files are then added in the
|
Chris@18
|
258 compressed file.
|
Chris@18
|
259 The adding of files is done by going through the file/dir list,
|
Chris@18
|
260 adding files per files, in a recursive way through the
|
Chris@18
|
261 directory. Each time a path need to be added/removed it is done
|
Chris@18
|
262 before writing the file header in the archive.
|
Chris@18
|
263
|
Chris@18
|
264 Method : add($p_filelist)
|
Chris@18
|
265 Description :
|
Chris@18
|
266 This method add the files / directories listed in $p_filelist at the
|
Chris@18
|
267 end of the existing archive. If the archive does not yet exists it
|
Chris@18
|
268 is created.
|
Chris@18
|
269 The $p_filelist parameter can be an array of string, each string
|
Chris@18
|
270 representing a filename or a directory name with their path if
|
Chris@18
|
271 needed. It can also be a single string with names separated by a
|
Chris@18
|
272 single blank.
|
Chris@18
|
273 See addModify() method for details and limitations.
|
Chris@18
|
274 Arguments :
|
Chris@18
|
275 $p_filelist : An array of filenames and directory names, or a single
|
Chris@18
|
276 string with names separated by a single blank space.
|
Chris@18
|
277 Return value :
|
Chris@18
|
278 true on success, false on error.
|
Chris@18
|
279 Sample 1 :
|
Chris@18
|
280 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
281 [...]
|
Chris@18
|
282 $v_list[0]="dev/file.txt";
|
Chris@18
|
283 $v_list[1]="dev/data/"; (Optional '/' at the end)
|
Chris@18
|
284 $v_list[2]="log/file.log";
|
Chris@18
|
285 $tar_object->add($v_list);
|
Chris@18
|
286 Sample 2 :
|
Chris@18
|
287 $tar_object = new Archive_Tar("tarname.tgz", true);
|
Chris@18
|
288 [...]
|
Chris@18
|
289 $v_list[0]="dev/file.txt";
|
Chris@18
|
290 $v_list[1]="dev/data/"; (Optional '/' at the end)
|
Chris@18
|
291 $v_list[2]="log/file.log";
|
Chris@18
|
292 $tar_object->add($v_list);
|
Chris@18
|
293 How it works :
|
Chris@18
|
294 Simply call the addModify() method with the right parameters.
|
Chris@18
|
295
|
Chris@18
|
296 Method : addString($p_filename, $p_string, $p_datetime, $p_params)
|
Chris@18
|
297 Description :
|
Chris@18
|
298 This method add a single string as a file at the
|
Chris@18
|
299 end of the existing archive. If the archive does not yet exists it
|
Chris@18
|
300 is created.
|
Chris@18
|
301 Arguments :
|
Chris@18
|
302 $p_filename : A string which contains the full filename path
|
Chris@18
|
303 that will be associated with the string.
|
Chris@18
|
304 $p_string : The content of the file added in the archive.
|
Chris@18
|
305 $p_datetime : (Optional) Timestamp of the file (default = now)
|
Chris@18
|
306 $p_params : (Optional) Various file metadata:
|
Chris@18
|
307 stamp - As above, timestamp of the file
|
Chris@18
|
308 mode - UNIX-style permissions (default 0600)
|
Chris@18
|
309 type - Is this a regular file or link (see TAR
|
Chris@18
|
310 format spec for how to create a hard/symlink)
|
Chris@18
|
311 uid - UNIX-style user ID (default 0 = root)
|
Chris@18
|
312 gid - UNIX-style group ID (default 0 = root)
|
Chris@18
|
313 Return value :
|
Chris@18
|
314 true on success, false on error.
|
Chris@18
|
315 Sample 1 :
|
Chris@18
|
316 $v_archive = & new Archive_Tar($p_filename);
|
Chris@18
|
317 $v_archive->setErrorHandling(PEAR_ERROR_PRINT);
|
Chris@18
|
318 $v_result = $v_archive->addString('data/test.txt', 'This is the text of the string');
|
Chris@18
|
319 $v_result = $v_archive->addString(
|
Chris@18
|
320 'data/test.sh',
|
Chris@18
|
321 "#!/bin/sh\necho 'Hello'",
|
Chris@18
|
322 time(),
|
Chris@18
|
323 array( "mode" => 0755, "uid" => 34 )
|
Chris@18
|
324 );
|
Chris@18
|
325
|
Chris@18
|
326
|
Chris@18
|
327 Method : extract($p_path = "")
|
Chris@18
|
328 Description :
|
Chris@18
|
329 This method extract all the content of the archive in the directory
|
Chris@18
|
330 indicated by $p_path.If $p_path is optional, if not set the archive
|
Chris@18
|
331 is extracted in the current directory.
|
Chris@18
|
332 While extracting a file, if the directory path does not exists it is
|
Chris@18
|
333 created.
|
Chris@18
|
334 See extractModify() for details and limitations.
|
Chris@18
|
335 Arguments :
|
Chris@18
|
336 $p_path : Optional path where the files/dir need to by extracted.
|
Chris@18
|
337 Return value :
|
Chris@18
|
338 true on success, false on error.
|
Chris@18
|
339 Sample :
|
Chris@18
|
340 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
341 $tar_object->extract();
|
Chris@18
|
342 How it works :
|
Chris@18
|
343 Simply call the extractModify() method with appropriate parameters.
|
Chris@18
|
344
|
Chris@18
|
345 Method : extractModify($p_path, $p_remove_path)
|
Chris@18
|
346 Description :
|
Chris@18
|
347 This method extract all the content of the archive in the directory
|
Chris@18
|
348 indicated by $p_path. When relevant the memorized path of the
|
Chris@18
|
349 files/dir can be modified by removing the $p_remove_path path at the
|
Chris@18
|
350 beginning of the file/dir path.
|
Chris@18
|
351 While extracting a file, if the directory path does not exists it is
|
Chris@18
|
352 created.
|
Chris@18
|
353 While extracting a file, if the file already exists it is replaced
|
Chris@18
|
354 without looking for last modification date.
|
Chris@18
|
355 While extracting a file, if the file already exists and is write
|
Chris@18
|
356 protected, the extraction is aborted.
|
Chris@18
|
357 While extracting a file, if a directory with the same name already
|
Chris@18
|
358 exists, the extraction is aborted.
|
Chris@18
|
359 While extracting a directory, if a file with the same name already
|
Chris@18
|
360 exists, the extraction is aborted.
|
Chris@18
|
361 While extracting a file/directory if the destination directory exist
|
Chris@18
|
362 and is write protected, or does not exist but can not be created,
|
Chris@18
|
363 the extraction is aborted.
|
Chris@18
|
364 If after extraction an extracted file does not show the correct
|
Chris@18
|
365 stored file size, the extraction is aborted.
|
Chris@18
|
366 When the extraction is aborted, a PEAR error text is set and false
|
Chris@18
|
367 is returned. However the result can be a partial extraction that may
|
Chris@18
|
368 need to be manually cleaned.
|
Chris@18
|
369 Arguments :
|
Chris@18
|
370 $p_path : The path of the directory where the files/dir need to by
|
Chris@18
|
371 extracted.
|
Chris@18
|
372 $p_remove_path : Part of the memorized path that can be removed if
|
Chris@18
|
373 present at the beginning of the file/dir path.
|
Chris@18
|
374 Return value :
|
Chris@18
|
375 true on success, false on error.
|
Chris@18
|
376 Sample :
|
Chris@18
|
377 // Imagine tarname.tar with files :
|
Chris@18
|
378 // dev/data/file.txt
|
Chris@18
|
379 // dev/data/log.txt
|
Chris@18
|
380 // readme.txt
|
Chris@18
|
381 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
382 $tar_object->extractModify("install", "dev");
|
Chris@18
|
383 // Files will be extracted there :
|
Chris@18
|
384 // install/data/file.txt
|
Chris@18
|
385 // install/data/log.txt
|
Chris@18
|
386 // install/readme.txt
|
Chris@18
|
387 How it works :
|
Chris@18
|
388 Open the archive and call a more generic function that can extract
|
Chris@18
|
389 only a part of the archive or all the archive.
|
Chris@18
|
390 See extractList() method for more details.
|
Chris@18
|
391
|
Chris@18
|
392 Method : extractInString($p_filename)
|
Chris@18
|
393 Description :
|
Chris@18
|
394 This method extract from the archive one file identified by $p_filename.
|
Chris@18
|
395 The return value is a string with the file content, or NULL on error.
|
Chris@18
|
396 Arguments :
|
Chris@18
|
397 $p_filename : The path of the file to extract in a string.
|
Chris@18
|
398 Return value :
|
Chris@18
|
399 a string with the file content or NULL.
|
Chris@18
|
400 Sample :
|
Chris@18
|
401 // Imagine tarname.tar with files :
|
Chris@18
|
402 // dev/data/file.txt
|
Chris@18
|
403 // dev/data/log.txt
|
Chris@18
|
404 // dev/readme.txt
|
Chris@18
|
405 $v_archive = & new Archive_Tar('tarname.tar');
|
Chris@18
|
406 $v_archive->setErrorHandling(PEAR_ERROR_PRINT);
|
Chris@18
|
407 $v_string = $v_archive->extractInString('dev/readme.txt');
|
Chris@18
|
408 echo $v_string;
|
Chris@18
|
409
|
Chris@18
|
410 Method : listContent()
|
Chris@18
|
411 Description :
|
Chris@18
|
412 This method returns an array of arrays that describe each
|
Chris@18
|
413 file/directory present in the archive.
|
Chris@18
|
414 The array is not sorted, so it show the position of the file in the
|
Chris@18
|
415 archive.
|
Chris@18
|
416 The file informations are :
|
Chris@18
|
417 $file[filename] : Name and path of the file/dir.
|
Chris@18
|
418 $file[mode] : File permissions (result of fileperms())
|
Chris@18
|
419 $file[uid] : user id
|
Chris@18
|
420 $file[gid] : group id
|
Chris@18
|
421 $file[size] : filesize
|
Chris@18
|
422 $file[mtime] : Last modification time (result of filemtime())
|
Chris@18
|
423 $file[typeflag] : "" for file, "5" for directory
|
Chris@18
|
424 Arguments :
|
Chris@18
|
425 Return value :
|
Chris@18
|
426 An array of arrays or 0 on error.
|
Chris@18
|
427 Sample :
|
Chris@18
|
428 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
429 if (($v_list = $tar_object->listContent()) != 0)
|
Chris@18
|
430 for ($i=0; $i<sizeof($v_list); $i++)
|
Chris@18
|
431 {
|
Chris@18
|
432 echo "Filename :'".$v_list[$i][filename]."'<br>";
|
Chris@18
|
433 echo " .size :'".$v_list[$i][size]."'<br>";
|
Chris@18
|
434 echo " .mtime :'".$v_list[$i][mtime]."' (".
|
Chris@18
|
435 date("l dS of F Y h:i:s A", $v_list[$i][mtime]).")<br>";
|
Chris@18
|
436 echo " .mode :'".$v_list[$i][mode]."'<br>";
|
Chris@18
|
437 echo " .uid :'".$v_list[$i][uid]."'<br>";
|
Chris@18
|
438 echo " .gid :'".$v_list[$i][gid]."'<br>";
|
Chris@18
|
439 echo " .typeflag :'".$v_list[$i][typeflag]."'<br>";
|
Chris@18
|
440 }
|
Chris@18
|
441 How it works :
|
Chris@18
|
442 Call the same function as an extract however with a flag to only go
|
Chris@18
|
443 through the archive without extracting the files.
|
Chris@18
|
444
|
Chris@18
|
445 Method : extractList($p_filelist, $p_path = "", $p_remove_path = "")
|
Chris@18
|
446 Description :
|
Chris@18
|
447 This method extract from the archive only the files indicated in the
|
Chris@18
|
448 $p_filelist. These files are extracted in the current directory or
|
Chris@18
|
449 in the directory indicated by the optional $p_path parameter.
|
Chris@18
|
450 If indicated the $p_remove_path can be used in the same way as it is
|
Chris@18
|
451 used in extractModify() method.
|
Chris@18
|
452 Arguments :
|
Chris@18
|
453 $p_filelist : An array of filenames and directory names, or a single
|
Chris@18
|
454 string with names separated by a single blank space.
|
Chris@18
|
455 $p_path : The path of the directory where the files/dir need to by
|
Chris@18
|
456 extracted.
|
Chris@18
|
457 $p_remove_path : Part of the memorized path that can be removed if
|
Chris@18
|
458 present at the beginning of the file/dir path.
|
Chris@18
|
459 Return value :
|
Chris@18
|
460 true on success, false on error.
|
Chris@18
|
461 Sample :
|
Chris@18
|
462 // Imagine tarname.tar with files :
|
Chris@18
|
463 // dev/data/file.txt
|
Chris@18
|
464 // dev/data/log.txt
|
Chris@18
|
465 // readme.txt
|
Chris@18
|
466 $tar_object = new Archive_Tar("tarname.tar");
|
Chris@18
|
467 $tar_object->extractList("dev/data/file.txt readme.txt", "install",
|
Chris@18
|
468 "dev");
|
Chris@18
|
469 // Files will be extracted there :
|
Chris@18
|
470 // install/data/file.txt
|
Chris@18
|
471 // install/readme.txt
|
Chris@18
|
472 How it works :
|
Chris@18
|
473 Go through the archive and extract only the files present in the
|
Chris@18
|
474 list.
|
Chris@18
|
475
|