\Horde_Compress_Zip

The Horde_Compress_zip class allows ZIP files to be created and read.

Summary

Methods
Properties
Constants
__construct()
compress()
compressDirectory()
decompress()
checkZipData()
$canCompress
$canDecompress
ZIP_LIST
ZIP_DATA
CTRL_DIR_HEADER
CTRL_DIR_END
FILE_HEADER
_getZipInfo()
_getZipData()
_unix2DOSTime()
_addToZipFile()
$_logger
$_methods
$_ctrldir
$_tmp
N/A
No private methods found
No private properties found
N/A

Constants

ZIP_LIST

ZIP_LIST

Return file list.

ZIP_DATA

ZIP_DATA

Return file data.

CTRL_DIR_HEADER

CTRL_DIR_HEADER

Beginning of central directory record.

CTRL_DIR_END

CTRL_DIR_END

End of central directory record.

FILE_HEADER

FILE_HEADER

Beginning of file contents.

Properties

$canCompress

$canCompress : boolean

Does this driver support compressing data?

Type

boolean

$canDecompress

$canDecompress : boolean

Does this driver support decompressing data?

Type

boolean

$_logger

$_logger : \Horde_Log_Logger

Logger

Type

\Horde_Log_Logger

$_methods

$_methods : array

ZIP compression methods.

Type

array

$_ctrldir

$_ctrldir : array

Temporary data for compressing files.

Type

array

$_tmp

$_tmp : resource

Temporary contents for compressing files.

Type

resource

Methods

__construct()

__construct(array  $options = array()) 

Constructor.

Parameters

array $options

Additional options for the compressor backend.

compress()

compress(array  $data, array  $params = array()) : mixed

Compresses the data.

Parameters

array $data

The data to compress. Requires an array of arrays. Each subarray should contain these fields:

  • data: (string/resource) The data to compress.
  • name: (string) The pathname to the file.
  • time: (integer) [optional] The timestamp to use for the file.
array $params

The parameter array.

  • stream: (boolean) If set, return a stream instead of a string. DEFAULT: Return string

Returns

mixed —

The ZIP file as either a string or a stream resource.

compressDirectory()

compressDirectory(string  $directory, array  $params = array()) : mixed

Compresses a directory.

Parameters

string $directory

The directory to recursively compress.

array $params

An array of arguments needed to compress the data.

Throws

\Horde_Compress_Exception

Returns

mixed —

The compressed data.

decompress()

decompress(mixed  $data, array  $params = array()) : mixed

Decompresses the data.

Parameters

mixed $data

The data to decompress.

array $params

The parameter array.

  • action: (integer) [REQUIRED] The action to take on the data. Either self::ZIP_LIST or self::ZIP_DATA.
  • info: (array) [REQUIRED for ZIP_DATA] The zipfile list.
  • key: (integer) [REQUIRED for ZIP_DATA] The position of the file in the archive list.

Throws

\Horde_Compress_Exception

Returns

mixed —

If action is self::ZIP_DATA, the uncompressed data. If action is self::ZIP_LIST, an array with the KEY as the position in the zipfile and these 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

checkZipData()

checkZipData(string  $data) : boolean

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

Parameters

string $data

The ZIP file data.

Returns

boolean —

True if valid, false if invalid.

_getZipInfo()

_getZipInfo(string  $data) : array

Get the list of files/data from the zip archive.

Parameters

string $data

The zipfile data.

Throws

\Horde_Compress_Exception

Returns

array —

See decompress() for the format.

_getZipData()

_getZipData(string  $data, array  $info, integer  $key) : string

Returns the data for a specific archived file.

Parameters

string $data

The zip archive contents.

array $info

The information array from _getZipInfo().

integer $key

The position of the file in the archive.

Returns

string —

The file data.

_unix2DOSTime()

_unix2DOSTime(integer  $unixtime = null) : integer

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).

Parameters

integer $unixtime

The current UNIX timestamp.

Returns

integer —

The current date in a 4-byte DOS format.

_addToZipFile()

_addToZipFile(array  $file) 

Adds a "file" to the ZIP archive.

Parameters

array $file

See self::createZipFile().