The ezcArchiveZip class implements the Zip archive format.
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 an entry 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:
Source for this file: /Archive/src/zip/zip.php
ezcArchive | --ezcArchiveZip
Version: | //autogentag// |
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. |
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. |
From ezcArchive | |
---|---|
protected |
ezcArchive::$completed
|
protected |
ezcArchive::$entries
|
protected |
ezcArchive::$entriesRead
|
protected |
ezcArchive::$file
|
protected |
ezcArchive::$fileNumber
|
protected |
ezcArchive::$options
|
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. |
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. |
Initializes the Zip archive and reads the entire archive.
The constructor opens the archive as a ezcArchiveCharacterFile.
Name | Type | Description |
---|---|---|
$file |
ezcArchiveCharacterFile |
Returns true because the ZIP algorithm can write.
Method | Description |
---|---|
ezcArchive::algorithmCanWrite() |
Returns true if writing to the archive is implemented, otherwise false. |
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.
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. |
Type | Description |
---|---|
ezcArchiveException |
if one of the files cannot be written to the archive. |
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. |
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:
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.
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. |
Type | 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 |
Method | Description |
---|---|
ezcArchive::appendToCurrent() |
Appends a file to the archive after the current entry. |
Returns the value which specifies a ZIP algorithm.
Method | Description |
---|---|
ezcArchive::getAlgorithm() |
Returns the algorithm that is used currently. |
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.
Name | Type | Description |
---|---|---|
$fileNumber |
int |
Returns the local header of the specified file number.
Name | Type | Description |
---|---|---|
$fileNumber |
int |
Type | Description |
---|---|
ezcArchiveException |
if the signature from the file is invalid |
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.
Type | Description |
---|---|
ezcArchiveException |
if the archive is closed |
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.
Type | 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 |
Creates and sets a new ezcArchiveCentralDirectoryEndHeader.
The new ezcArchiveCentralDirectoryEndHeader is based on the current file position, the centralHeaderPositions, and the number of entries read.
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.
Name | Type | Description |
---|---|---|
$fileNumber |
int |
Type | Description |
---|---|
ezcBaseFilePermissionException |
if the file is read-only or if the current algorithm cannot write |
Method | Description |
---|---|
ezcArchive::truncate() |
Truncates the archive to $fileNumber of files. |
Writes the file data from the current entry to the given file.
Name | Type | Description |
---|---|---|
$targetPath |
string | The absolute or relative path of the target file. |
Method | Description |
---|---|
ezcArchive::writeCurrentDataToFile() |
Writes the file data from the current entry to the given file. |
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.
Name | Type | Description |
---|---|---|
$fileNumber |
int | |
$writeTo |
string |
Type | Description |
---|---|
ezcArchiveChecksumException |
if the checksum is invalid from the created file. |