Zip

Implements ExtractableInterface

ZIP format adapter for the Archive package

The ZIP compression code is partially based on code from: Eric Mueller [email protected] http://www.zend.com/codex.php?id=535&single=1

Deins125 [email protected] http://www.zend.com/codex.php?id=470&single=1

The ZIP compression date code is partially based on code from Peter Listiak [email protected]

This class is inspired from and draws heavily in code and concept from the Compress package of The Horde Project http://www.horde.org

contributor

Chuck Hagenbuch [email protected]

Michael Slusarz [email protected]

Michael Cochrane [email protected]

since

1.0

package

Joomla Framework

Methods

__construct

Create a new Archive object.

__construct(array|\ArrayAccess options = []) : 
since

1.0

throws

InvalidArgumentException

Arguments

options

array<string|int, mixed>|ArrayAccessAn array of options or an object that implements \ArrayAccess

Response

mixed

addToZipFile

Adds a "file" to the ZIP archive.

addToZipFile(mixed||string|int &file, mixed||string|int &contents, mixed||string|int &ctrldir) : 
since

1.0

todo

Review and finish implementation

Arguments

file

array<string|int, mixed>File data array to add

contents

array<string|int, mixed>An array of existing zipped files.

ctrldir

array<string|int, mixed>An array of central directory information.

Response

void

checkZipData

Checks to see if the data is a valid ZIP file.

checkZipData( data) : 
since

1.0

Arguments

data

stringZIP archive data buffer.

Response

boolTrue if valid, false if invalid.

create

Create a ZIP compressed file from an array of file data.

create( archive, mixed||string|int files) : 
since

1.0

todo

Finish Implementation

Arguments

archive

stringPath to save archive.

files

array<string|int, mixed>Array of files to add to archive.

Response

boolTrue if successful.

createZipFile

Creates the ZIP file.

createZipFile(mixed||string|int contents, mixed||string|int ctrlDir,  path) : 

Official ZIP file format: http://www.pkware.com/appnote.txt

since

1.0

todo

Review and finish implementation

Arguments

contents

array<string|int, mixed>An array of existing zipped files.

ctrlDir

array<string|int, mixed>An array of central directory information.

path

stringThe path to store the archive.

Response

boolTrue if successful

extract

Extract a ZIP compressed file to a given path

extract( archive,  destination) : 
since

1.0

throws

RuntimeException

Arguments

archive

stringPath to ZIP archive to extract

destination

stringPath to extract archive into

Response

boolTrue if successful

extractCustom

Extract a ZIP compressed file to a given path using a php based algorithm that only requires zlib support

extractCustom( archive,  destination) : 
since

1.0

throws

RuntimeException

Arguments

archive

stringPath to ZIP archive to extract.

destination

stringPath to extract archive into.

Response

boolTrue if successful

extractNative

Extract a ZIP compressed file to a given path using native php api calls for speed

extractNative( archive,  destination) : 
throws

RuntimeException

since

1.0

Arguments

archive

stringPath to ZIP archive to extract

destination

stringPath to extract archive into

Response

boolTrue on success

getFileData

Returns the file data for a file by offset in the ZIP archive

getFileData( key) : 
since

1.0

Arguments

key

intThe position of the file in the archive.

Response

stringUncompressed file data buffer.

hasNativeSupport

Method to determine if the server has native zip support for faster handling

hasNativeSupport() : 
static
since

1.0

Response

boolTrue if php has native ZIP support

isBelow

Check if a path is below a given destination path

isBelow( destination,  path) : 
since

1.1.10

Arguments

destination

stringThe destination path

path

stringThe path to be checked

Response

bool

isSupported

Tests whether this adapter can unpack files on this computer.

isSupported() : 
static
since

1.0

Response

boolTrue if supported

readZipInfo

Get the list of files/data from a ZIP archive buffer.

readZipInfo( data) : 
KEY: Position in zipfile
VALUES: 'attr'  --  File attributes
        'crc'   --  CRC checksum
        'csize' --  Compressed file size
        'date'  --  File modification time
        'name'  --  Filename
        'method'--  Compression method
        'size'  --  Original file size
        'type'  --  File type
since

1.0

throws

RuntimeException

Arguments

data

stringThe ZIP archive buffer.

Response

boolTrue on success

unix2DosTime

Converts a UNIX timestamp to a 4-byte DOS date and time format (date in high 2-bytes, time in low 2-bytes allowing magnitude comparison).

unix2DosTime( unixtime = null) : 
since

1.0

Arguments

unixtime

intThe current UNIX timestamp.

Response

intThe current date in a 4-byte DOS format.

Constants

METHODS

ZIP compression methods.

Value [0x0 => 'None', 0x1 => 'Shrunk', 0x2 => 'Super Fast', 0x3 => 'Fast', 0x4 => 'Normal', 0x5 => 'Maximum', 0x6 => 'Imploded', 0x8 => 'Deflated']
since

1.0

Type(s)

array<string|int, mixed>

CTRL_DIR_HEADER

Beginning of central directory record.

Value "PK\x01\x02"
since

1.0

Type(s)

string

CTRL_DIR_END

End of central directory record.

Value "PK\x05\x06\x00\x00\x00\x00"
since

1.0

Type(s)

string

FILE_HEADER

Beginning of file contents.

Value "PK\x03\x04"
since

1.0

Type(s)

string

Properties

data

ZIP file data buffer

since

1.0

Type(s)

string

metadata

ZIP file metadata array

since

1.0

Type(s)

array<string|int, mixed>

options

Holds the options array.

since

1.0

Type(s)

array<string|int, mixed>|ArrayAccess