PHP Class Archive_Tar, JxLib

Inheritance: extends PEAR
Mostrar archivo Open project: JxLib/JxLib Class Usage Examples

Public Properties

Property Type Description
$_compress if true, the Tar file will be gzipped
$_compress_type Type of compression : 'none', 'gz' or 'bz2'
$_file descriptor
$_separator Explode separator
$_tarname Name of the Tar
$_temp_tarname Local Tar name of a remote Tar (http:// or ftp://)

Public Methods

Method Description
Archive_Tar ( string $p_tarname, string $p_compress = null ) 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.
_Archive_Tar ( ) {{{ destructor
_addFile ( $p_filename, &$p_header, $p_add_dir, $p_remove_dir ) {{{ _addFile()
_addList ( $p_list, $p_add_dir, $p_remove_dir ) {{{ _addList()
_addString ( $p_filename, $p_string ) {{{ _addString()
_append ( $p_filelist, $p_add_dir = '', $p_remove_dir = '' ) {{{ _append()
_cleanFile ( ) {{{ _cleanFile()
_close ( ) {{{ _close()
_dirCheck ( string $p_dir ) : boolean Check if a directory exists and create it (including parent dirs) if not.
_error ( $p_message ) {{{ _error()
_extractInString ( string $p_filename ) : a This method extract from the archive one file identified by $p_filename.
_extractList ( $p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path ) {{{ _extractList()
_isArchive ( $p_filename = NULL ) {{{ _isArchive()
_jumpBlock ( $p_len = null ) {{{ _jumpBlock()
_maliciousFilename ( string $file ) : boolean Detect and report a malicious file name
_openAppend ( ) {{{ _openAppend()
_openRead ( ) {{{ _openRead()
_openReadWrite ( ) {{{ _openReadWrite()
_openWrite ( ) {{{ _openWrite()
_pathReduction ( string $p_dir ) : string Compress path by changing for example "/dir/foo/.
_readBlock ( ) {{{ _readBlock()
_readHeader ( $v_binary_data, &$v_header ) {{{ _readHeader()
_readLongHeader ( &$v_header ) {{{ _readLongHeader()
_translateWinPath ( $p_path, $p_remove_disk_letter = true ) {{{ _translateWinPath()
_warning ( $p_message ) {{{ _warning()
_writeBlock ( $p_binary_data, $p_len = null ) {{{ _writeBlock()
_writeFooter ( ) {{{ _writeFooter()
_writeHeader ( $p_filename, $p_stored_filename ) {{{ _writeHeader()
_writeHeaderBlock ( $p_filename, $p_size, $p_mtime, $p_perms, $p_type = '', $p_uid, $p_gid ) {{{ _writeHeaderBlock()
_writeLongHeader ( $p_filename ) {{{ _writeLongHeader()
add ( array $p_filelist ) : true This method add the files / directories that are listed in $p_filelist in the archive. If the archive does not exist it is created.
addModify ( array $p_filelist, string $p_add_dir, string $p_remove_dir = '' ) : true 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.
addString ( string $p_filename, string $p_string ) : true 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.
create ( array $p_filelist ) : true This method creates the archive file and add the files / directories that are listed in $p_filelist.
createModify ( array $p_filelist, string $p_add_dir, string $p_remove_dir = '' ) : boolean This method creates the archive file and add the files / directories that are listed in $p_filelist.
extract ( $p_path = '' ) {{{ extract()
extractInString ( string $p_filename ) : a This method extract from the archive one file identified by $p_filename.
extractList ( array $p_filelist, string $p_path = '', string $p_remove_path = '' ) : 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.
extractModify ( string $p_path, string $p_remove_path ) : boolean 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.
listContent ( ) {{{ listContent()
setAttribute ( ) : true 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, ',');

Method Details

Archive_Tar() public method

If the compress argument is set the tar will be read or created as a gzip or bz2 compressed TAR file.
public Archive_Tar ( string $p_tarname, string $p_compress = null )
$p_tarname string The name of the tar archive to create
$p_compress string can be null, 'gz' or 'bz2'. This parameter indicates if gzip or bz2 compression is required. For compatibility reason the boolean value 'true' means 'gz'.

_Archive_Tar() public method

{{{ destructor
public _Archive_Tar ( )

_addFile() public method

{{{ _addFile()
public _addFile ( $p_filename, &$p_header, $p_add_dir, $p_remove_dir )

_addList() public method

{{{ _addList()
public _addList ( $p_list, $p_add_dir, $p_remove_dir )

_addString() public method

{{{ _addString()
public _addString ( $p_filename, $p_string )

_append() public method

{{{ _append()
public _append ( $p_filelist, $p_add_dir = '', $p_remove_dir = '' )

_cleanFile() public method

{{{ _cleanFile()
public _cleanFile ( )

_close() public method

{{{ _close()
public _close ( )

_dirCheck() public method

Check if a directory exists and create it (including parent dirs) if not.
public _dirCheck ( string $p_dir ) : boolean
$p_dir string directory to check
return boolean TRUE if the directory exists or was created

_error() public method

{{{ _error()
public _error ( $p_message )

_extractInString() public method

The return value is a string with the file content, or NULL on error.
public _extractInString ( string $p_filename ) : a
$p_filename string The path of the file to extract in a string.
return a string with the file content or NULL.

_extractList() public method

{{{ _extractList()
public _extractList ( $p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path )

_isArchive() public method

{{{ _isArchive()
public _isArchive ( $p_filename = NULL )

_jumpBlock() public method

{{{ _jumpBlock()
public _jumpBlock ( $p_len = null )

_maliciousFilename() public method

Detect and report a malicious file name
public _maliciousFilename ( string $file ) : boolean
$file string
return boolean

_openAppend() public method

{{{ _openAppend()
public _openAppend ( )

_openRead() public method

{{{ _openRead()
public _openRead ( )

_openReadWrite() public method

{{{ _openReadWrite()
public _openReadWrite ( )

_openWrite() public method

{{{ _openWrite()
public _openWrite ( )

_pathReduction() public method

./bar" to "/dir/bar", rand emove double slashes.
public _pathReduction ( string $p_dir ) : string
$p_dir string path to reduce
return string reduced path

_readBlock() public method

{{{ _readBlock()
public _readBlock ( )

_readHeader() public method

{{{ _readHeader()
public _readHeader ( $v_binary_data, &$v_header )

_readLongHeader() public method

{{{ _readLongHeader()
public _readLongHeader ( &$v_header )

_translateWinPath() public method

{{{ _translateWinPath()
public _translateWinPath ( $p_path, $p_remove_disk_letter = true )

_warning() public method

{{{ _warning()
public _warning ( $p_message )

_writeBlock() public method

{{{ _writeBlock()
public _writeBlock ( $p_binary_data, $p_len = null )

_writeFooter() public method

{{{ _writeFooter()
public _writeFooter ( )

_writeHeader() public method

{{{ _writeHeader()
public _writeHeader ( $p_filename, $p_stored_filename )

_writeHeaderBlock() public method

{{{ _writeHeaderBlock()
public _writeHeaderBlock ( $p_filename, $p_size, $p_mtime, $p_perms, $p_type = '', $p_uid, $p_gid )

_writeLongHeader() public method

{{{ _writeLongHeader()
public _writeLongHeader ( $p_filename )

add() public method

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.
See also: createModify()
public add ( array $p_filelist ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
return true on success, false on error.

addModify() public method

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.
public addModify ( array $p_filelist, string $p_add_dir, string $p_remove_dir = '' ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
$p_add_dir string A string which contains a path to be added to the memorized path of each element in the list.
$p_remove_dir string A string which contains a path to be removed from the memorized path of each element in the list, when relevant.
return true on success, false on error.

addString() public method

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.
public addString ( string $p_filename, string $p_string ) : true
$p_filename string A string which contains the full filename path that will be associated with the string.
$p_string string The content of the file added in the archive.
return true on success, false on error.

create() public method

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.
See also: createModify()
public create ( array $p_filelist ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
return true on success, false on error.

createModify() public method

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.
See also: addModify()
public createModify ( array $p_filelist, string $p_add_dir, string $p_remove_dir = '' ) : boolean
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
$p_add_dir string A string which contains a path to be added to the memorized path of each element in the list.
$p_remove_dir string A string which contains a path to be removed from the memorized path of each element in the list, when relevant.
return boolean true on success, false on error.

extract() public method

{{{ extract()
public extract ( $p_path = '' )

extractInString() public method

The return value is a string with the file content, or NULL on error.
public extractInString ( string $p_filename ) : a
$p_filename string The path of the file to extract in a string.
return a string with the file content or NULL.

extractList() public method

If indicated the $p_remove_path can be used in the same way as it is used in extractModify() method.
See also: extractModify()
public extractList ( array $p_filelist, string $p_path = '', string $p_remove_path = '' ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
$p_path string The path of the directory where the files/dir need to by extracted.
$p_remove_path string Part of the memorized path that can be removed if present at the beginning of the file/dir path.
return true on success, false on error.

extractModify() public method

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.
See also: extractList()
public extractModify ( string $p_path, string $p_remove_path ) : boolean
$p_path string The path of the directory where the files/dir need to by extracted.
$p_remove_path string Part of the memorized path that can be removed if present at the beginning of the file/dir path.
return boolean true on success, false on error.

listContent() public method

{{{ listContent()
public listContent ( )

setAttribute() public method

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, ',');
public setAttribute ( ) : true
return true on success, false on error.

Property Details

$_compress public_oe property

if true, the Tar file will be gzipped
public $_compress

$_compress_type public_oe property

Type of compression : 'none', 'gz' or 'bz2'
public $_compress_type

$_file public_oe property

descriptor
public $_file

$_separator public_oe property

Explode separator
public $_separator

$_tarname public_oe property

Name of the Tar
public $_tarname

$_temp_tarname public_oe property

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