Path

ez components / documentation / api reference / 1.0.1 / archive


eZ Components 1.0.1

Archive: ezcArchiveZip

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

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:
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 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:
protected  ezcArchive::$completed
protected  ezcArchive::$entries
protected  ezcArchive::$entriesRead
protected  ezcArchive::$file
protected  ezcArchive::$fileNumber

Method Summary

public ezcArchiveZip __construct( $file )
Initializes the Zip archive and reads the entire archive.
public void algorithmCanWrite( )
public void appendToCurrent( $files, $prefix )
public void getAlgorithm( )
public string getFileData( $fileNumber )
Returns the file data of the given fileNumber.
protected void readEntireArchive( )
Reads the entire archive and creates all the entries.
protected void setEndRecord( )
Creates and sets a new ezcArchiveCentralDirectoryEndHeader.
public void truncate( [$fileNumber = 0] )
protected void writeCurrentDataToFile( $targetPath )
public void writeFile( $fileNumber, $writeTo )
Reads the file data from the archive and writes it the the $writeTo file.

Inherited Methods

From ezcArchive :
public abstract bool ezcArchive::algorithmCanWrite()
Returns true if writing to the archive is implemented, otherwise false.
public void ezcArchive::append()
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.
public abstract void ezcArchive::appendToCurrent()
Appends a file to the archive after the current entry.
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.
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 bool ezcArchive::isWritable()
Returns true if it is possible to write to the archive, 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 abstract void ezcArchive::truncate()
Truncate 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 mixed ezcArchive::__get()
Returns the property $name.
public void ezcArchive::__set()
Sets the property $name to $value.
public string ezcArchive::__toString()
Returns a string which represents all the entries from the archive.

Methods

__construct

ezcArchiveZip __construct( $file )
Initializes the Zip archive and reads the entire archive.
The constructor opens the archive as a ezcArchiveCharacterFile.

algorithmCanWrite

void algorithmCanWrite( )

Redefinition of

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

appendToCurrent

void appendToCurrent( $files, $prefix )

Parameters

Name Type Description
$files  
$prefix  

Redefinition of

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

getAlgorithm

void getAlgorithm( )

Redefinition of

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

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  

readEntireArchive

void readEntireArchive( )
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.
The central directory structure gives us extra information about the stored file like: symlinks and permissions.

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

void truncate( [ $fileNumber = 0] )

Parameters

Name Type Description
$fileNumber  

Redefinition of

Method Description
ezcArchive::truncate() Truncate the archive to $fileNumber of files.

writeCurrentDataToFile

void writeCurrentDataToFile( $targetPath )

Parameters

Name Type Description
$targetPath  

Redefinition of

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

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

ClassDescription
ezcArchiveChecksumException if the checksum is invalid from the created file.

Last updated: Fri, 02 Nov 2007