Archive: ezcArchiveZip
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcArchiveZip
|
The ezcArchiveZip class implements the Zip archive format. [
source]
Implemented Interfaces
- Iterator (internal interface)
ezcArchiveZip is a subclass from
ezcArchive that provides the common interface. Zip algorithm specific methods are implemented in this class.
ezcArchiveZip tries on creation to read the entire archive. Every
ezcArchiveEntry will be appended to the
ezcArchive::$entries array. (ezcArchiveTarV7 archive format reads only anentry when needed the first time.)
All the archive entries are read, because we need to find the ezcArchiveCentralDirectoryHeader that contains extra file information. Some other Zip implementations search back from the end of the archive, but:
- Not all of them take the comment section at the end of the archive into account.
- The file pointer can only forward, so they seek over the entire archive anyway.
The current implementation can handle Non-Zip64 archives. The following extra Zip information can be read:
- The Unix Extra field.
- The Unix Extra field 2.
- The Universal Timestamp field.
Parents
ezcArchive
|
--ezcArchiveZip
Inherited Constants
From
ezcArchive:
Member Variables
|
protected array(int) |
$centralHeaderPositions
Stores the byte number where the central directory header starts (fileNumber is the index of the array). |
|
protected array(ezcArchiveCentralDirectoryHeader) |
$centralHeaders
Stores the ezcArchiveCentralDirectoryHeader for each entry. |
|
protected ezcArchiveCentralDirectoryEndHeader |
$endRecord
Stores the ezcArchiveCentralDirectoryEndHeader. |
|
protected array(int) |
$localHeaderPositions
Stores the byte number where the local file header starts for each entry. |
|
protected array(ezcArchiveLocalFileHeader) |
$localHeaders
Stores the ezcArchiveLocalFileHeader for each entry. |
Inherited Member Variables
From
ezcArchive:
Method Summary
|
public ezcArchiveZip |
__construct(
$file )
Initializes the Zip archive and reads the entire archive. |
|
public bool |
algorithmCanWrite(
)
Returns true because the ZIP algorithm can write. |
|
public bool |
append(
$files, $prefix )
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 bool |
appendToCurrent(
$files, $prefix )
Appends a file to the archive after the current entry. |
|
public int |
getAlgorithm(
)
Returns the value which specifies a ZIP algorithm. |
|
public string |
getFileData(
$fileNumber )
Returns the file data of the given fileNumber. |
|
public void |
getLocalHeader(
$fileNumber )
Returns the local header of the specified file number. |
|
public bool |
isWritable(
)
Returns true if it is possible to write to the archive, otherwise false. |
|
protected void |
readCentralHeaders(
)
Reads the entire archive and creates all the entries. |
|
protected void |
setEndRecord(
)
Creates and sets a new ezcArchiveCentralDirectoryEndHeader. |
|
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 |
writeFile(
$fileNumber, $writeTo )
Reads the file data from the archive and writes it the the $writeTo file. |
Inherited Methods
From
ezcArchive :
Methods
__construct
ezcArchiveZip __construct(
$file )
Initializes the Zip archive and reads the entire archive.
The constructor opens the archive as a ezcArchiveCharacterFile.
Parameters
| Name |
Type |
Description |
$file |
ezcArchiveCharacterFile |
|
algorithmCanWrite
bool algorithmCanWrite(
)
Returns true because the ZIP algorithm can write.
See also:
ezcArchiveZip::isWritable().
Redefinition of
append
bool append(
string|array(string)
$files, string
$prefix )
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.
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. |
Throws
| Class | Description |
ezcArchiveException |
if one of the files cannot be written to the archive. |
See also:
ezcArchiveZip::appendToCurrent().
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. |
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 );
2.
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. |
Throws
| Class | Description |
ezcArchiveException |
if the archive is closed or read-only |
ezcBaseFileNotFoundException |
if one of the specified files is missing |
ezcBaseFilePermissionException |
if the archive is not writable |
Redefinition of
getAlgorithm
int getAlgorithm(
)
Returns the value which specifies a ZIP algorithm.
Redefinition of
getFileData
string getFileData(
int
$fileNumber )
Returns the file data of the given fileNumber.
This method doesn't handle compression and reads the whole file in memory. This method is used to get the symbolic links, since these are stored in files.
For larger or compressed files, use the
writeFile() method.
Parameters
| Name |
Type |
Description |
$fileNumber |
int |
|
getLocalHeader
void getLocalHeader(
int
$fileNumber )
Returns the local header of the specified file number.
Parameters
| Name |
Type |
Description |
$fileNumber |
int |
|
Throws
| Class | Description |
ezcArchiveException |
if the signature from the file is invalid |
isWritable
bool isWritable(
)
Returns true if it is possible to write to the archive, otherwise false.
This method returns false if the archive is read-only, the algorithm didn't implement any write methods, or both.
Throws
| Class | Description |
ezcArchiveException |
if the archive is closed |
See also:
ezcArchiveZip::algorithmCanWrite().
readCentralHeaders
void readCentralHeaders(
)
Reads the entire archive and creates all the entries.
To find the central directory structure we need to read all the headers. Some algorithms search backwards, but these don't expect comments at the end of the archive.
The central directory structure gives us extra information about the stored file like: symlinks and permissions.
Throws
| Class | Description |
ezcArchiveException |
if the comment length is different than 0 or if the signature from the file is invalid or if the directory central header or size are missing |
setEndRecord
void setEndRecord(
)
Creates and sets a new ezcArchiveCentralDirectoryEndHeader.
The new ezcArchiveCentralDirectoryEndHeader is based on the current file position, the centralHeaderPositions, and the number of entries read.
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 |
|
Throws
| Class | Description |
ezcBaseFilePermissionException |
if the file is read-only or if the current algorithm cannot write |
Redefinition of
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
writeFile
void writeFile(
int
$fileNumber, string
$writeTo )
Reads the file data from the archive and writes it the the $writeTo file.
The data from the entry with $fileNumber is read from the archive. If the data is compressed or deflated it will be, respectively, decompressed or inflated.
Parameters
| Name |
Type |
Description |
$fileNumber |
int |
|
$writeTo |
string |
|
Throws
| Class | Description |
ezcArchiveChecksumException |
if the checksum is invalid from the created file. |
Last updated: Tue, 02 Dec 2008