## Apache Zeta Components Manual :: Docs For Class ezcArchiveV7Tar

### Archive::ezcArchiveV7Tar

### Class ezcArchiveV7Tar

The ezcArchiveV7Tar class implements the Tar v7 archive format.

ezcArchiveV7Tar is a subclass from ezcArchive that provides the common interface. Tar v7 algorithm specific methods are implemented in this class.

ezcArchiveV7Tar reads on creation only the first ezcArchiveEntry from the archive. When needed next entries are read.

The V7 Tar algorithm is most basic implementation of Tar. This format has the following characteristics:

- Filenames up to 100 characters.
- Stores the file permissions.
- Stores the owner and group by ID.
- Stores the last modification time.
- Can archive: regular files and symbolic links.
- Maximum file size: 8 Gygabyte.

Source for this file: /Archive/src/tar/v7.php

    ezcArchive
       |
       --ezcArchiveV7Tar

Version: | //autogentag//

### Descendants

Child Class | Description
--- | ---
ezcArchiveUstarTar | The ezcArchiveUstarTar class implements the Tar ustar archive format.

### Constants

`BLOCK_SIZE = 512` | Amount of bytes in a block.

### Inherited Constants

From ezcArchive:
`ezcArchive::BZIP2` | BZIP2 compression format.
`ezcArchive::GZIP` | Gnu ZIP compression format.
`ezcArchive::TAR` | Normal tar archive.
`ezcArchive::TAR_GNU` | GNU tar archive.
`ezcArchive::TAR_PAX` | PAX tar archive.
`ezcArchive::TAR_USTAR` | USTAR tar archive.
`ezcArchive::TAR_V7` | Tar version 7 archive.
`ezcArchive::ZIP` | ZIP archive.

### Member Variables

protected int | `$addedBlocks = 0` Stores the number of added blocks.
protected bool | `$addedBlocksNotReliable = false` Specifies if unreliable blocks were added.
protected int | `$blockFactor = 20` Tar archives have always $blockFactor of blocks.
protected bool | `$hasNullBlocks` Specifies if the archive contains null blocks.
protected array(int) | `$headerPositions` Stores the block number where the header starts. The fileNumber is the index of the array.
protected array(ezcArchiveV7Header) | `$headers` Stores all the headers from the archive. The first header of the archive has index zero. The ezcArchiveV7Header or a subclass from this header is stored in the array. createTarHeader() will create the correct header.

### Inherited Member Variables

From ezcArchive
protected | `ezcArchive::$completed`
protected | `ezcArchive::$entries`
protected | `ezcArchive::$entriesRead`
protected | `ezcArchive::$file`
protected | `ezcArchive::$fileNumber`
protected | `ezcArchive::$options`

### Method Summary

public ezcArchiveV7Tar | `__construct( $file , [ $blockFactor = 20] )` Initializes the Tar and tries to read the first entry from the archive.
public void | `__destruct( )` Closes the archive.
public bool | `algorithmCanWrite( )` Returns true because the TAR_V7 algorithm can write.
public bool | `append( $files , $prefix )` Append a file or directory to the end of the archive. Multiple files or directory can be added to the archive when an array is used as input parameter.
protected bool | `appendHeaderAndFileToCurrent( $entry )` Appends the given ezcArchiveBlockFile $file and ezcArchiveEntry $entry to the archive file.
protected void | `appendNullBlocks( )` Appends zero or more null blocks to the end of the archive, so that it matches the $blockFactor.
public bool | `appendToCurrent( $files , $prefix )` Appends a file to the archive after the current entry.
public void | `close( )` Closes the archive correctly.
protected ezcArchiveV7Header | `createTarHeader( [ $file = null] )` Creates the a new tar header for this class.
public int | `getAlgorithm( )` Returns the value which specifies a TAR_V7 algorithm.
protected bool | `readCurrentFromArchive( )` Read the current entry from the archive.
public bool | `truncate( [ $fileNumber = 0] )` Truncates the archive to $fileNumber of files.
protected bool | `writeCurrentDataToFile( $targetPath )` Writes the file data from the current entry to the given file.
public void | `writeEnd( )` Writes the end of the archive.

### Inherited Methods

From ezcArchive
public abstract bool | `ezcArchive::algorithmCanWrite()` Returns true if writing to the archive is implemented, otherwise false.
public abstract bool | `ezcArchive::append()` Appends a file or directory to the end of the archive. Multiple files or directory can be added to the archive when an array is used as input parameter.
public abstract bool | `ezcArchive::appendToCurrent()` Appends a file to the archive after the current entry.
public void | `ezcArchive::close()` Close the current archive.
protected void | `ezcArchive::createDefaultDirectory()` Creates all the directories needed to create the file $file.
protected static ezcArchive | `ezcArchive::createInstance()` Returns an instance of the archive with the given type.
public ezcArchiveEntry | `ezcArchive::current()` Returns the current ezcArchiveEntry if it is valid, otherwise false is returned.
public void | `ezcArchive::extract()` Extract entries from the archive to the target directory.
public bool | `ezcArchive::extractCurrent()` Extract the current entry to which the iterator points.
public abstract int | `ezcArchive::getAlgorithm()` Returns the algorithm that is used currently.
protected ezcArchiveEntry | `ezcArchive::getEntries()` Get the file entries from the archive.
public array(string) | `ezcArchive::getListing()` Returns an array that lists the content of the archive.
public static ezcArchive | `ezcArchive::getTarInstance()` Open a tar instance.
public static ezcArchive | `ezcArchive::getZipInstance()` Open a zip instance. This method is made public for testing purposes, and should not be used.
public bool | `ezcArchive::isEmpty()` Returns true if the current archive is empty, otherwise false.
public int | `ezcArchive::key()` Returns the current key, entry number, if it is valid, otherwise false is returned.
public ezcArchiveEntry | `ezcArchive::next()` Forwards the iterator to the next entry.
public static ezcArchive | `ezcArchive::open()` Returns a new ezcArchive instance.
public void | `ezcArchive::rewind()` Rewinds the iterator to the first entry.
public bool | `ezcArchive::seek()` Search for the entry number.
public void | `ezcArchive::setOptions()` This method associates a new $options object with this archive.
public abstract bool | `ezcArchive::truncate()` Truncates the archive to $fileNumber of files.
public bool | `ezcArchive::valid()` Returns true if the iterator points to a valid entry, otherwise false.
protected abstract void | `ezcArchive::writeCurrentDataToFile()` Writes the file data from the current entry to the given file.
public string | `ezcArchive::__toString()` Returns a string which represents all the entries from the archive.

### Methods

#### __construct

ezcArchiveV7Tar __construct( $file , [int $blockFactor = 20] )

Initializes the Tar and tries to read the first entry from the archive.

At initialization it sets the blockFactor to $blockFactor. Each tar archive has always $blockFactor of blocks ( 0, $blockFactor, 2 * $blockFactor, etc ).

The Tar archive works with blocks, so therefore the first parameter expects the archive as a blockFile.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$file` | ezcArchiveBlockFile |
`$blockFactor` | int |

##### Redefined in descendants as:

Method | Description
--- | ---
`ezcArchiveUstarTar::__construct()` | Initializes the Tar and tries to read the first entry from the archive.
`ezcArchiveGnuTar::__construct()` | Initializes the Tar and tries to read the first entry from the archive.
`ezcArchivePaxTar::__construct()` | Initializes the Tar and tries to read the first entry from the archive.

#### __destruct

void __destruct( )

Closes the archive.

#### algorithmCanWrite

bool algorithmCanWrite( )

Returns true because the TAR_V7 algorithm can write.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::algorithmCanWrite()` | Returns true if writing to the archive is implemented, otherwise false.

##### Redefined in descendants as:

Method | Description
--- | ---
`ezcArchiveUstarTar::algorithmCanWrite()` | Returns true because the TAR_USTAR algorithm can write.
`ezcArchiveGnuTar::algorithmCanWrite()` | Returns false because the TAR_PAX algorithm cannot write (yet).
`ezcArchivePaxTar::algorithmCanWrite()` | Returns false because the TAR_PAX algorithm cannot write (yet).

#### append

bool append( string|array(string) $files , string $prefix )

Append a file or directory to the end of the archive. Multiple files or directory can be added to the archive when an array is used as input parameter.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$files` | string|array(string) | Add the files and or directories to the archive.
`$prefix` | string | First part of the path used in $files.

##### Exceptions:

Type | Description
--- | ---
`ezcArchiveWriteException` | if one of the files cannot be written to the archive.
`ezcFileReadException` | if one of the files cannot be read from the local filesystem.
`ezcArchiveException` | if the archive is closed.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::append()` | Appends a file or directory to the end of the archive. Multiple files or directory can be added to the archive when an array is used as input parameter.

#### appendHeaderAndFileToCurrent

bool appendHeaderAndFileToCurrent( ezcArchiveEntry $entry )

Appends the given ezcArchiveBlockFile $file and ezcArchiveEntry $entry to the archive file.

The $entry will be used to create the correct header, whereas the $file contains the raw data that should be append to the archive.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$entry` | ezcArchiveEntry |

#### appendNullBlocks

void appendNullBlocks( )

Appends zero or more null blocks to the end of the archive, so that it matches the $blockFactor.

If the archive has already the correct size, no null blocks will be appended. Otherwise as many null blocks are appended (up to $blockFactor - 1) so that it matches the $blockFactor.

#### appendToCurrent

bool appendToCurrent( string|array(string) $files , string $prefix )

Appends a file to the archive after the current entry.

One or multiple files can be added directly after the current file. The remaining entries after the current are removed from the archive!

The $files can either be a string or an array of strings. Which, respectively, represents a single file or multiple files.

$prefix specifies the begin part of the $files path that should not be included in the archive. The files in the archive are always stored relatively.

Example:

1. $tar=ezcArchive ("/tmp/my_archive.tar", ezcArchive ::TAR);
3. // Append two files to the end of the archive.
4. $tar-> seek (0,SEEK_END);
5. $tar-> appendToCurrent (array("/home/rb/file1.txt","/home/rb/file2.txt"),"/home/rb/");

When multiple files are added to the archive at the same time, thus using an array, does not necessarily produce the same archive as repeatively adding one file to the archive. For example, the Tar archive format, can detect that files hardlink to each other and will store it in a more efficient way.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$files` | string|array(string) | Array or a single path to a file.
`$prefix` | string | First part of the path used in $files.

##### Exceptions:

Type | Description
--- | ---
`ezcArchiveWriteException` | if one of the files cannot be written to the archive.
`ezcFileReadException` | if one of the files cannot be read from the local filesystem.
`ezcArchiveException` | if the archive is closed.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::appendToCurrent()` | Appends a file to the archive after the current entry.

#### close

void close( )

Closes the archive correctly.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::close()` | Close the current archive.

#### createTarHeader

ezcArchiveV7Header createTarHeader( [string|null $file = null] )

Creates the a new tar header for this class.

Usually this class is reimplemented by other Tar algorithms, and therefore it returns another Tar header.

This method expects an ezcArchiveBlockFile that points to the header that should be read (and created). If null is given as block file, an empty header will be created.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$file` | string|null |

##### Redefined in descendants as:

Method | Description
--- | ---
`ezcArchiveUstarTar::createTarHeader()` | Creates the a new ustar tar header for this class.
`ezcArchiveGnuTar::createTarHeader()` | Creates the a new pax tar header for this class.
`ezcArchivePaxTar::createTarHeader()` | Creates the a new pax tar header for this class.

#### getAlgorithm

int getAlgorithm( )

Returns the value which specifies a TAR_V7 algorithm.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::getAlgorithm()` | Returns the algorithm that is used currently.

##### Redefined in descendants as:

Method | Description
--- | ---
`ezcArchiveUstarTar::getAlgorithm()` | Returns the value which specifies a TAR_USTAR algorithm.
`ezcArchiveGnuTar::getAlgorithm()` | Returns the value which specifies a TAR_GNU algorithm.
`ezcArchivePaxTar::getAlgorithm()` | Returns the value which specifies a TAR_PAX algorithm.

#### readCurrentFromArchive

bool readCurrentFromArchive( )

Read the current entry from the archive.

The current entry from the archive is read, if possible. This method will set the $completed to true, if the end of the archive is reached. The $entriesRead will be increased, if the entry is correctly read.

##### Exceptions:

Type | Description
--- | ---
`ezcArchiveBlockSizeException` | if the file is empty or if the file is not valid

#### truncate

bool truncate( [int $fileNumber = 0] )

Truncates the archive to $fileNumber of files.

The $fileNumber parameter specifies the amount of files that should remain. If the default value, zero, is used then the entire archive file is cleared.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$fileNumber` | int |

##### Exceptions:

Type | Description
--- | ---
`ezcBaseFilePermissionException` | if the file is read-only or if the current algorithm cannot write
`ezcArchiveException` | if the archive is closed

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::truncate()` | Truncates the archive to $fileNumber of files.

#### writeCurrentDataToFile

bool writeCurrentDataToFile( string $targetPath )

Writes the file data from the current entry to the given file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$targetPath` | string | The absolute or relative path of the target file.

##### Redefinition of:

Method | Description
--- | ---
`ezcArchive::writeCurrentDataToFile()` | Writes the file data from the current entry to the given file.

#### writeEnd

void writeEnd( )

Writes the end of the archive.

##### Exceptions:

Type | Description
--- | ---
`ezcArchiveException` | if the archive is closed

Documentation generated by phpDocumentor 1.4.3