Documentation

Horde_Compress_Zip extends Horde_Compress_Base
in package

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

Tags
author

Chuck Hagenbuch chuck@horde.org

author

Michael Cochrane mike@graftonhall.co.nz

author

Michael Slusarz slusarz@horde.org

category

Horde

copyright

2000-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Table of Contents

CTRL_DIR_END  = "PK\x05\x06\x00\x00\x00\x00"
End of central directory record.
CTRL_DIR_HEADER  = "PK\x01\x02"
Beginning of central directory record.
FILE_HEADER  = "PK\x03\x04"
Beginning of file contents.
ZIP_DATA  = 2
Return file data.
ZIP_LIST  = 1
Return file list.
$canCompress  : bool
Does this driver support compressing data?
$canDecompress  : bool
Does this driver support decompressing data?
$_ctrldir  : array<string|int, mixed>
Temporary data for compressing files.
$_logger  : Horde_Log_Logger
Logger
$_methods  : array<string|int, mixed>
ZIP compression methods.
$_tmp  : resource
Temporary contents for compressing files.
__construct()  : mixed
Constructor.
checkZipData()  : bool
Checks to see if the data is a valid ZIP file.
compress()  : mixed
Compresses the data.
compressDirectory()  : mixed
Compresses a directory.
decompress()  : mixed
Decompresses the data.
_addToZipFile()  : mixed
Adds a "file" to the ZIP archive.
_getZipData()  : string
Returns the data for a specific archived file.
_getZipInfo()  : array<string|int, mixed>
Get the list of files/data from the zip archive.
_unix2DOSTime()  : int
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).

Constants

CTRL_DIR_END

End of central directory record.

public mixed CTRL_DIR_END = "PK\x05\x06\x00\x00\x00\x00"

CTRL_DIR_HEADER

Beginning of central directory record.

public mixed CTRL_DIR_HEADER = "PK\x01\x02"

FILE_HEADER

Beginning of file contents.

public mixed FILE_HEADER = "PK\x03\x04"

ZIP_DATA

Return file data.

public mixed ZIP_DATA = 2
Tags
see

decompress().

ZIP_LIST

Return file list.

public mixed ZIP_LIST = 1
Tags
see

decompress().

Properties

$canCompress

Does this driver support compressing data?

public bool $canCompress = \true

$canDecompress

Does this driver support decompressing data?

public bool $canDecompress = \true

$_ctrldir

Temporary data for compressing files.

protected array<string|int, mixed> $_ctrldir

$_logger

Logger

protected Horde_Log_Logger $_logger

$_methods

ZIP compression methods.

protected array<string|int, mixed> $_methods = array(0x0 => 'None', 0x1 => 'Shrunk', 0x2 => 'Super Fast', 0x3 => 'Fast', 0x4 => 'Normal', 0x5 => 'Maximum', 0x6 => 'Imploded', 0x8 => 'Deflated')

$_tmp

Temporary contents for compressing files.

protected resource $_tmp

Methods

__construct()

Constructor.

public __construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
$options : array<string|int, mixed> = array()

Additional options for the compressor backend.

Return values
mixed

checkZipData()

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

public checkZipData(string $data) : bool
Parameters
$data : string

The ZIP file data.

Return values
bool

True if valid, false if invalid.

compress()

Compresses the data.

public compress(array<string|int, mixed> $data[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$data : array<string|int, mixed>

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.
$params : array<string|int, mixed> = array()

The parameter array.

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

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

compressDirectory()

Compresses a directory.

public compressDirectory(string $directory[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$directory : string

The directory to recursively compress.

$params : array<string|int, mixed> = array()

An array of arguments needed to compress the data.

Tags
since

Horde_Compress 2.2.0

throws
Horde_Compress_Exception
Return values
mixed

The compressed data.

decompress()

Decompresses the data.

public decompress(mixed $data[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$data : mixed

The data to decompress.

$params : array<string|int, mixed> = array()

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.
Tags
throws
Horde_Compress_Exception
Return values
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

_addToZipFile()

Adds a "file" to the ZIP archive.

protected _addToZipFile(array<string|int, mixed> $file) : mixed
Parameters
$file : array<string|int, mixed>

See self::createZipFile().

Return values
mixed

_getZipData()

Returns the data for a specific archived file.

protected _getZipData(string $data, array<string|int, mixed> $info, int $key) : string
Parameters
$data : string

The zip archive contents.

$info : array<string|int, mixed>

The information array from _getZipInfo().

$key : int

The position of the file in the archive.

Return values
string

The file data.

_getZipInfo()

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

protected _getZipInfo(string $data) : array<string|int, mixed>
Parameters
$data : string

The zipfile data.

Tags
throws
Horde_Compress_Exception
Return values
array<string|int, mixed>

See decompress() for the format.

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

protected _unix2DOSTime([int $unixtime = null ]) : int
Parameters
$unixtime : int = null

The current UNIX timestamp.

Return values
int

The current date in a 4-byte DOS format.

Search results