home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / tmp / Archive_Tar-1.3.2 / docs / Archive_Tar.txt
Encoding:
Text File  |  2007-01-06  |  17.9 KB  |  462 lines

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