Open Journal Systems  3.3.0
Archive_Tar Class Reference
Inheritance diagram for Archive_Tar:
PEAR

Public Member Functions

 __construct ($p_tarname, $p_compress=null, $buffer_length=512)
 
 __destruct ()
 
 _addFile ($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $v_stored_filename=null)
 
 _addList ($p_list, $p_add_dir, $p_remove_dir)
 
 _addString ($p_filename, $p_string, $p_datetime=false, $p_params=array())
 
 _append ($p_filelist, $p_add_dir='', $p_remove_dir='')
 
 _cleanFile ()
 
 _close ()
 
 _dirCheck ($p_dir)
 
 _error ($p_message)
 
 _extractList ( $p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path, $p_preserve=false, $p_symlinks=true)
 
 _isArchive ($p_filename=null)
 
 _jumpBlock ($p_len=null)
 
 _openAppend ()
 
 _openRead ()
 
 _openReadWrite ()
 
 _openWrite ()
 
 _readBlock ()
 
 _readHeader ($v_binary_data, &$v_header)
 
 _readLongHeader (&$v_header)
 
 _translateWinPath ($p_path, $p_remove_disk_letter=true)
 
 _warning ($p_message)
 
 _writeBlock ($p_binary_data, $p_len=null)
 
 _writeFooter ()
 
 _writeHeader ($p_filename, $p_stored_filename)
 
 _writeHeaderBlock ( $p_filename, $p_size, $p_mtime=0, $p_perms=0, $p_type='', $p_uid=0, $p_gid=0)
 
 _writeLongHeader ($p_filename, $is_link=false)
 
 add ($p_filelist)
 
 addModify ($p_filelist, $p_add_dir, $p_remove_dir='')
 
 addString ($p_filename, $p_string, $p_datetime=false, $p_params=array())
 
 create ($p_filelist)
 
 createModify ($p_filelist, $p_add_dir, $p_remove_dir='')
 
 extract ($p_path='', $p_preserve=false, $p_symlinks=true)
 
 extractInString ($p_filename)
 
 extractList ($p_filelist, $p_path='', $p_remove_path='', $p_preserve=false, $p_symlinks=true)
 
 extractModify ($p_path, $p_remove_path, $p_preserve=false, $p_symlinks=true)
 
 listContent ()
 
 setAttribute ()
 
 setIgnoreList ($list)
 
 setIgnoreRegexp ($regexp)
 
- Public Member Functions inherited from PEAR
 __call ($method, $arguments)
 
 __construct ($error_class=null)
 
 _checkDelExpect ($error_code)
 
 _PEAR ()
 
 delExpect ($error_code)
 
 expectError ($code=' *')
 
 PEAR ($error_class=null)
 
 popExpect ()
 

Data Fields

 $_compress = false
 
 $_compress_type = 'none'
 
 $_file = 0
 
 $_fmt = ''
 
 $_ignore_regexp = ''
 
 $_separator = ' '
 
 $_tarname = ''
 
 $_temp_tarname = ''
 
 $error_object = null
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_handler = ''
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Protected Attributes

 $buffer_length
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static __callStatic ($method, $arguments)
 
static getSourceDateEpoch ()
 
static & getStaticProperty ($class, $var)
 
static isError ($data, $code=null)
 
static loadExtension ($ext)
 
static registerShutdownFunc ($func, $args=array())
 
static staticPopErrorHandling ()
 
static staticPushErrorHandling ($mode, $options=null)
 
- Static Protected Member Functions inherited from PEAR
static _popErrorHandling ($object)
 
static _pushErrorHandling ($object, $mode, $options=null)
 
static _raiseError ($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 
static _setErrorHandling ( $object, $mode=null, $options=null)
 
static _throwError ($object, $message=null, $code=null, $userinfo=null)
 
- Static Protected Attributes inherited from PEAR
static $bivalentMethods
 

Detailed Description

Definition at line 80 of file Tar.php.

Constructor & Destructor Documentation

◆ __construct()

Archive_Tar::__construct (   $p_tarname,
  $p_compress = null,
  $buffer_length = 512 
)

Archive_Tar Class constructor. This flavour of the constructor only declare a new Archive_Tar object, identifying it by the name of the tar file. If the compress argument is set the tar will be read or created as a gzip or bz2 compressed TAR file.

Parameters
string$p_tarnameThe name of the tar archive to create
string$p_compresscan be null, 'gz', 'bz2' or 'lzma2'. This parameter indicates if gzip, bz2 or lzma2 compression is required. For compatibility reason the boolean value 'true' means 'gz'.
int$buffer_lengthLength of the read buffer in bytes
Returns
bool

Definition at line 180 of file Tar.php.

References $buffer_length, _error(), and PEAR\loadExtension().

◆ __destruct()

Archive_Tar::__destruct ( )

Definition at line 286 of file Tar.php.

References _close().

Member Function Documentation

◆ _addFile()

Archive_Tar::_addFile (   $p_filename,
$p_header,
  $p_add_dir,
  $p_remove_dir,
  $v_stored_filename = null 
)
Parameters
string$p_filename
mixed$p_header
string$p_add_dir
string$p_remove_dir
null$v_stored_filename
Returns
bool

Definition at line 1247 of file Tar.php.

References $buffer_length, _error(), _isArchive(), _translateWinPath(), _warning(), _writeBlock(), and _writeHeader().

Referenced by _addList().

◆ _addList()

Archive_Tar::_addList (   $p_list,
  $p_add_dir,
  $p_remove_dir 
)
Parameters
array$p_list
string$p_add_dir
string$p_remove_dir
Returns
bool

Definition at line 1161 of file Tar.php.

References _addFile(), _error(), _translateWinPath(), and _warning().

Referenced by _append(), and createModify().

◆ _addString()

Archive_Tar::_addString (   $p_filename,
  $p_string,
  $p_datetime = false,
  $p_params = array() 
)
Parameters
string$p_filename
string$p_string
bool$p_datetime
array$p_params
Returns
bool

Definition at line 1333 of file Tar.php.

References _error(), _translateWinPath(), _writeBlock(), and _writeHeaderBlock().

Referenced by addString().

◆ _append()

Archive_Tar::_append (   $p_filelist,
  $p_add_dir = '',
  $p_remove_dir = '' 
)
Parameters
$p_filelist
string$p_add_dir
string$p_remove_dir
Returns
bool

Definition at line 2399 of file Tar.php.

References _addList(), _close(), _openAppend(), and _writeFooter().

Referenced by addModify().

◆ _cleanFile()

Archive_Tar::_cleanFile ( )
Returns
bool

Definition at line 997 of file Tar.php.

References _close().

Referenced by createModify().

◆ _close()

Archive_Tar::_close ( )
Returns
bool

Definition at line 956 of file Tar.php.

References _error().

Referenced by __destruct(), _append(), _cleanFile(), addString(), createModify(), extractInString(), extractList(), extractModify(), and listContent().

◆ _dirCheck()

Archive_Tar::_dirCheck (   $p_dir)

Check if a directory exists and create it (including parent dirs) if not.

Parameters
string$p_dirdirectory to check
Returns
bool true if the directory exists or was created

Definition at line 2422 of file Tar.php.

References _error().

Referenced by _extractList().

◆ _error()

◆ _extractList()

Archive_Tar::_extractList (   $p_path,
$p_list_detail,
  $p_mode,
  $p_file_list,
  $p_remove_path,
  $p_preserve = false,
  $p_symlinks = true 
)
Parameters
string$p_path
string$p_list_detail
string$p_mode
string$p_file_list
string$p_remove_path
bool$p_preserve
bool$p_symlinks
Returns
bool

Definition at line 1958 of file Tar.php.

References _dirCheck(), _error(), _isArchive(), _jumpBlock(), _readBlock(), _readHeader(), _readLongHeader(), _translateWinPath(), and _warning().

Referenced by extractList(), extractModify(), and listContent().

◆ _isArchive()

Archive_Tar::_isArchive (   $p_filename = null)
Parameters
string$p_filename
Returns
bool

Definition at line 789 of file Tar.php.

References $_tarname.

Referenced by _addFile(), _extractList(), addModify(), and addString().

◆ _jumpBlock()

Archive_Tar::_jumpBlock (   $p_len = null)
Parameters
null$p_len
Returns
bool

Definition at line 1105 of file Tar.php.

References _error(), and _readBlock().

Referenced by _extractList().

◆ _openAppend()

Archive_Tar::_openAppend ( )
Returns
bool

Definition at line 2259 of file Tar.php.

Referenced by _append(), and addString().

◆ _openRead()

Archive_Tar::_openRead ( )
Returns
bool

Definition at line 839 of file Tar.php.

References $_tarname, $_temp_tarname, and _error().

Referenced by extractInString(), extractList(), extractModify(), and listContent().

◆ _openReadWrite()

Archive_Tar::_openReadWrite ( )
Returns
bool

Definition at line 910 of file Tar.php.

References _error().

◆ _openWrite()

Archive_Tar::_openWrite ( )
Returns
bool

Definition at line 801 of file Tar.php.

References _error().

Referenced by addString(), and createModify().

◆ _readBlock()

Archive_Tar::_readBlock ( )
Returns
null|string

Definition at line 1073 of file Tar.php.

References _error().

Referenced by _extractList(), _jumpBlock(), and _readLongHeader().

◆ _readHeader()

Archive_Tar::_readHeader (   $v_binary_data,
$v_header 
)
Parameters
mixed$v_binary_data
mixed$v_header
Returns
bool

Definition at line 1698 of file Tar.php.

References _error().

Referenced by _extractList(), and _readLongHeader().

◆ _readLongHeader()

Archive_Tar::_readLongHeader ( $v_header)
Parameters
$v_header
Returns
bool

Definition at line 1843 of file Tar.php.

References _error(), _readBlock(), and _readHeader().

Referenced by _extractList().

◆ _translateWinPath()

Archive_Tar::_translateWinPath (   $p_path,
  $p_remove_disk_letter = true 
)
Parameters
$p_path
bool$p_remove_disk_letter
Returns
string

Definition at line 2501 of file Tar.php.

Referenced by _addFile(), _addList(), _addString(), and _extractList().

◆ _warning()

Archive_Tar::_warning (   $p_message)
Parameters
string$p_message

Definition at line 780 of file Tar.php.

Referenced by _addFile(), _addList(), and _extractList().

◆ _writeBlock()

Archive_Tar::_writeBlock (   $p_binary_data,
  $p_len = null 
)
Parameters
mixed$p_binary_data
integer$p_len
Returns
bool

Definition at line 1020 of file Tar.php.

References _error().

Referenced by _addFile(), _addString(), _writeFooter(), _writeHeader(), _writeHeaderBlock(), and _writeLongHeader().

◆ _writeFooter()

Archive_Tar::_writeFooter ( )
Returns
bool

Definition at line 1145 of file Tar.php.

References _writeBlock().

Referenced by _append(), addString(), and createModify().

◆ _writeHeader()

Archive_Tar::_writeHeader (   $p_filename,
  $p_stored_filename 
)
Parameters
string$p_filename
string$p_stored_filename
Returns
bool

Definition at line 1385 of file Tar.php.

References _writeBlock(), and _writeLongHeader().

Referenced by _addFile().

◆ _writeHeaderBlock()

Archive_Tar::_writeHeaderBlock (   $p_filename,
  $p_size,
  $p_mtime = 0,
  $p_perms = 0,
  $p_type = '',
  $p_uid = 0,
  $p_gid = 0 
)
Parameters
string$p_filename
int$p_size
int$p_mtime
int$p_perms
string$p_type
int$p_uid
int$p_gid
Returns
bool

Definition at line 1508 of file Tar.php.

References _writeBlock(), and _writeLongHeader().

Referenced by _addString().

◆ _writeLongHeader()

Archive_Tar::_writeLongHeader (   $p_filename,
  $is_link = false 
)
Parameters
string$p_filename
Returns
bool

Definition at line 1617 of file Tar.php.

References _writeBlock().

Referenced by _writeHeader(), and _writeHeaderBlock().

◆ add()

Archive_Tar::add (   $p_filelist)

This method add the files / directories that are listed in $p_filelist in the archive. If the archive does not exist it is created. The method return false and a PEAR error text. The files and directories listed are only added at the end of the archive, even if a file with the same name is already archived. See also createModify() method for more details.

Parameters
array$p_filelistAn array of filenames and directory names, or a single string with names separated by a single blank space.
Returns
true on success, false on error.
See also
createModify() @access public

Definition at line 337 of file Tar.php.

References addModify().

◆ addModify()

Archive_Tar::addModify (   $p_filelist,
  $p_add_dir,
  $p_remove_dir = '' 
)

This method add the files / directories listed in $p_filelist at the end of the existing archive. If the archive does not yet exists it is created. The $p_filelist parameter can be an array of string, each string representing a filename or a directory name with their path if needed. It can also be a single string with names separated by a single blank. The path indicated in $p_remove_dir will be removed from the memorized path of each file / directory listed when this path exists. By default nothing is removed (empty path '') The path indicated in $p_add_dir will be added at the beginning of the memorized path of each file / directory listed. However it can be set to empty ''. The adding of a path is done after the removing of path. The path add/remove ability enables the user to prepare an archive for extraction in a different path than the origin files are. If a file/dir is already in the archive it will only be added at the end of the archive. There is no update of the existing archived file/dir. However while extracting the archive, the last file will replace the first one. This results in a none optimization of the archive size. If a file/dir does not exist the file/dir is ignored. However an error text is send to PEAR error. If a file/dir is not readable the file/dir is ignored. However an error text is send to PEAR error.

Parameters
array$p_filelistAn array of filenames and directory names, or a single string with names separated by a single blank space.
string$p_add_dirA string which contains a path to be added to the memorized path of each element in the list.
string$p_remove_dirA string which contains a path to be removed from the memorized path of each element in the list, when relevant.
Returns
true on success, false on error.

Definition at line 478 of file Tar.php.

References _append(), _error(), _isArchive(), and createModify().

Referenced by add().

◆ addString()

Archive_Tar::addString (   $p_filename,
  $p_string,
  $p_datetime = false,
  $p_params = array() 
)

This method add a single string as a file at the end of the existing archive. If the archive does not yet exists it is created.

Parameters
string$p_filenameA string which contains the full filename path that will be associated with the string.
string$p_stringThe content of the file added in the archive.
bool | int$p_datetimeA custom date/time (unix timestamp) for the file (optional).
array$p_paramsAn array of optional params: stamp => the datetime (replaces datetime above if it exists) mode => the permissions on the file (600 by default) type => is this a link? See the tar specification for details. (default = regular file) uid => the user ID of the file (default = 0 = root) gid => the group ID of the file (default = 0 = root)
Returns
true on success, false on error.

Definition at line 531 of file Tar.php.

References _addString(), _close(), _isArchive(), _openAppend(), _openWrite(), and _writeFooter().

◆ create()

Archive_Tar::create (   $p_filelist)

This method creates the archive file and add the files / directories that are listed in $p_filelist. If a file with the same name exist and is writable, it is replaced by the new tar. The method return false and a PEAR error text. The $p_filelist parameter can be an array of string, each string representing a filename or a directory name with their path if needed. It can also be a single string with names separated by a single blank. For each directory added in the archive, the files and sub-directories are also added. See also createModify() method for more details.

Parameters
array$p_filelistAn array of filenames and directory names, or a single string with names separated by a single blank space.
Returns
true on success, false on error.
See also
createModify()

Definition at line 316 of file Tar.php.

References createModify().

◆ createModify()

Archive_Tar::createModify (   $p_filelist,
  $p_add_dir,
  $p_remove_dir = '' 
)

This method creates the archive file and add the files / directories that are listed in $p_filelist. If the file already exists and is writable, it is replaced by the new tar. It is a create and not an add. If the file exists and is read-only or is a directory it is not replaced. The method return false and a PEAR error text. The $p_filelist parameter can be an array of string, each string representing a filename or a directory name with their path if needed. It can also be a single string with names separated by a single blank. The path indicated in $p_remove_dir will be removed from the memorized path of each file / directory listed when this path exists. By default nothing is removed (empty path '') The path indicated in $p_add_dir will be added at the beginning of the memorized path of each file / directory listed. However it can be set to empty ''. The adding of a path is done after the removing of path. The path add/remove ability enables the user to prepare an archive for extraction in a different path than the origin files are. See also addModify() method for file adding properties.

Parameters
array$p_filelistAn array of filenames and directory names, or a single string with names separated by a single blank space.
string$p_add_dirA string which contains a path to be added to the memorized path of each element in the list.
string$p_remove_dirA string which contains a path to be removed from the memorized path of each element in the list, when relevant.
Returns
boolean true on success, false on error.
See also
addModify()

Definition at line 406 of file Tar.php.

References _addList(), _cleanFile(), _close(), _error(), _openWrite(), and _writeFooter().

Referenced by addModify(), and create().

◆ extract()

Archive_Tar::extract (   $p_path = '',
  $p_preserve = false,
  $p_symlinks = true 
)
Parameters
string$p_path
bool$p_preserve
bool$p_symlinks
Returns
bool

Definition at line 348 of file Tar.php.

References extractModify().

◆ extractInString()

Archive_Tar::extractInString (   $p_filename)

This method extract from the archive one file identified by $p_filename. The return value is a string with the file content, or NULL on error.

Parameters
string$p_filenameThe path of the file to extract in a string.
Returns
a string with the file content or NULL.

Definition at line 625 of file Tar.php.

References _close(), and _openRead().

◆ extractList()

Archive_Tar::extractList (   $p_filelist,
  $p_path = '',
  $p_remove_path = '',
  $p_preserve = false,
  $p_symlinks = true 
)

This method extract from the archive only the files indicated in the $p_filelist. These files are extracted in the current directory or in the directory indicated by the optional $p_path parameter. If indicated the $p_remove_path can be used in the same way as it is used in extractModify() method.

Parameters
array$p_filelistAn array of filenames and directory names, or a single string with names separated by a single blank space.
string$p_pathThe path of the directory where the files/dir need to by extracted.
string$p_remove_pathPart of the memorized path that can be removed if present at the beginning of the file/dir path.
boolean$p_preservePreserve user/group ownership of files
boolean$p_symlinksAllow symlinks.
Returns
true on success, false on error.
See also
extractModify()

Definition at line 658 of file Tar.php.

References _close(), _error(), _extractList(), and _openRead().

◆ extractModify()

Archive_Tar::extractModify (   $p_path,
  $p_remove_path,
  $p_preserve = false,
  $p_symlinks = true 
)

This method extract all the content of the archive in the directory indicated by $p_path. When relevant the memorized path of the files/dir can be modified by removing the $p_remove_path path at the beginning of the file/dir path. While extracting a file, if the directory path does not exists it is created. While extracting a file, if the file already exists it is replaced without looking for last modification date. While extracting a file, if the file already exists and is write protected, the extraction is aborted. While extracting a file, if a directory with the same name already exists, the extraction is aborted. While extracting a directory, if a file with the same name already exists, the extraction is aborted. While extracting a file/directory if the destination directory exist and is write protected, or does not exist but can not be created, the extraction is aborted. If after extraction an extracted file does not show the correct stored file size, the extraction is aborted. When the extraction is aborted, a PEAR error text is set and false is returned. However the result can be a partial extraction that may need to be manually cleaned.

Parameters
string$p_pathThe path of the directory where the files/dir need to by extracted.
string$p_remove_pathPart of the memorized path that can be removed if present at the beginning of the file/dir path.
boolean$p_preservePreserve user/group ownership of files
boolean$p_symlinksAllow symlinks.
Returns
boolean true on success, false on error.
See also
extractList()

Definition at line 596 of file Tar.php.

References _close(), _extractList(), and _openRead().

Referenced by extract().

◆ listContent()

Archive_Tar::listContent ( )
Returns
array|int

Definition at line 356 of file Tar.php.

References _close(), _extractList(), and _openRead().

◆ setAttribute()

Archive_Tar::setAttribute ( )

This method set specific attributes of the archive. It uses a variable list of parameters, in the format attribute code + attribute values : $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ',');

Returns
true on success, false on error.

Definition at line 695 of file Tar.php.

References _error().

◆ setIgnoreList()

Archive_Tar::setIgnoreList (   $list)

This method sets the regular expression for ignoring all files and directories matching the filenames in the array list at import, for example: $arch->setIgnoreList(array('CVS', '.svn', 'bin/tool'));

Parameters
array$lista list of file or directory names to ignore

@access public

Definition at line 762 of file Tar.php.

References setIgnoreRegexp().

◆ setIgnoreRegexp()

Archive_Tar::setIgnoreRegexp (   $regexp)

This method sets the regular expression for ignoring files and directories at import, for example: $arch->setIgnoreRegexp("#CVS|\.svn#");

Parameters
string$regexpregular expression defining which files or directories to ignore

Definition at line 748 of file Tar.php.

Referenced by setIgnoreList().

Field Documentation

◆ $_compress

boolean Archive_Tar::$_compress = false

if true, the Tar file will be gzipped

Definition at line 96 of file Tar.php.

◆ $_compress_type

string Archive_Tar::$_compress_type = 'none'

Type of compression : 'none', 'gz', 'bz2' or 'lzma2'

Definition at line 104 of file Tar.php.

◆ $_file

file Archive_Tar::$_file = 0

descriptor

Definition at line 120 of file Tar.php.

◆ $_fmt

string Archive_Tar::$_fmt = ''

Format for data extraction

Definition at line 154 of file Tar.php.

◆ $_ignore_regexp

string Archive_Tar::$_ignore_regexp = ''

regular expression for ignoring files or directories

Definition at line 136 of file Tar.php.

◆ $_separator

string Archive_Tar::$_separator = ' '

Explode separator

Definition at line 112 of file Tar.php.

◆ $_tarname

string Archive_Tar::$_tarname = ''

Name of the Tar

Definition at line 88 of file Tar.php.

Referenced by _isArchive(), and _openRead().

◆ $_temp_tarname

string Archive_Tar::$_temp_tarname = ''

Local Tar name of a remote Tar (http:// or ftp://)

Definition at line 128 of file Tar.php.

Referenced by _openRead().

◆ $buffer_length

int Archive_Tar::$buffer_length
protected

Length of the read buffer in bytes

Definition at line 162 of file Tar.php.

Referenced by __construct(), and _addFile().

◆ $error_object

object Archive_Tar::$error_object = null

PEAR_Error object

Definition at line 144 of file Tar.php.


The documentation for this class was generated from the following file: