PHP Класс ZipStream\ZipStream

Streamed, dynamically generated zip archives.
Автор: Paul Duncan ([email protected])
Автор: Jonatan Männchen ([email protected])
Автор: Jesse Donat ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$cdr_ofs integer
$files array
$ofs integer
$opt array Global Options

Защищенные свойства (Protected)

Свойство Тип Описание
$need_headers boolean
$output_name null | String

Открытые методы

Метод Описание
__construct ( String $name = null, array $opt = [] ) Create a new ZipStream object.
addFile ( String $name, String $data, array $opt = [] ) addFile
addFileFromPath ( String $name, String $path, array $opt = [] ) : void addFileFromPath
addFileFromStream ( String $name, Resource $stream, array $opt = [] ) : void addFile_from_stream
finish ( ) : void finish

Защищенные методы

Метод Описание
addCdr ( array $opt = null ) : void Add CDR (Central Directory Record) footer.
addCdrEof ( array $opt = null ) : void Send CDR EOF (Central Directory Record End-of-File) record.
addCdrFile ( array $args ) : void Send CDR record for specified file.
addDataDescriptorHeader ( integer $len, integer $zlen, String $crc ) : integer
addFileHeader ( String $name, Array &$opt, integer $meth, string $crc, integer $zlen, integer $len, Hex $genb ) : integer Create and send zip header for this file.
addLargeFile ( String $name, String $path, array $opt = [] ) : void Add a large file from the given path.
clear ( ) : void Clear all internal variables. Note that the stream object is not usable after this.
dostime ( integer $when ) : integer Convert a UNIX timestamp to a DOS timestamp.
isLargeFile ( string $path ) : boolean Is this file larger than large_file_size?
packFields ( array $fields ) : string Create a format string and argument list for pack(), then call pack() and return the result.
send ( String $str ) : void Send string, sending HTTP headers if necessary.
sendHttpHeaders ( ) : void Send HTTP headers for this stream.

Приватные методы

Метод Описание
addToCdr ( String $name, Array $opt, integer $meth, string $crc, integer $zlen, integer $len, integer $rec_len, Hex $genb ) : integer Save file attributes for trailing CDR record.

Описание методов

__construct() публичный Метод

Parameters:
public __construct ( String $name = null, array $opt = [] )
$name String - Name of output file (optional).
$opt array - Hash of archive options (optional, see "Archive Options" below). Archive Options: comment - Comment for this archive. content_type - HTTP Content-Type. Defaults to 'application/x-zip'. content_disposition - HTTP Content-Disposition. Defaults to 'attachment; filename=\"FILENAME\"', where FILENAME is the specified filename. large_file_size - Size, in bytes, of the largest file to try and load into memory (used by addFileFromPath()). Large files may also be compressed differently; see the 'large_file_method' option. large_file_method - How to handle large files. Legal values are 'store' (the default), or 'deflate'. Store sends the file raw and is significantly faster, while 'deflate' compresses the file and is much, much slower. Note that deflate must compress the file twice and extremely slow. sendHttpHeaders - Boolean indicating whether or not to send the HTTP headers for this file. Note that content_type and content_disposition do nothing if you are not sending HTTP headers. Large File Support: By default, the method addFileFromPath() will send send files larger than 20 megabytes along raw rather than attempting to compress them. You can change both the maximum size and the compression behavior using the large_file_* options above, with the following caveats: * For "small" files (e.g. files smaller than large_file_size), the memory use can be up to twice that of the actual file. In other words, adding a 10 megabyte file to the archive could potentially occupty 20 megabytes of memory. * Enabling compression on large files (e.g. files larger than large_file_size) is extremely slow, because ZipStream has to pass over the large file once to calculate header information, and then again to compress and send the actual data. Examples: // create a new zip file named 'foo.zip' $zip = new ZipStream('foo.zip'); // create a new zip file named 'bar.zip' with a comment $zip = new ZipStream('bar.zip', array( 'comment' => 'this is a comment for the zip file.', )); Notes: If you do not set a filename, then this library _DOES NOT_ send HTTP headers by default. This behavior is to allow software to send its own headers (including the filename), and still use this library.

addCdr() защищенный Метод

Add CDR (Central Directory Record) footer.
protected addCdr ( array $opt = null ) : void
$opt array
Результат void

addCdrEof() защищенный Метод

Send CDR EOF (Central Directory Record End-of-File) record.
protected addCdrEof ( array $opt = null ) : void
$opt array
Результат void

addCdrFile() защищенный Метод

Send CDR record for specified file.
protected addCdrFile ( array $args ) : void
$args array
Результат void

addDataDescriptorHeader() защищенный Метод

protected addDataDescriptorHeader ( integer $len, integer $zlen, String $crc ) : integer
$len integer
$zlen integer
$crc String
Результат integer $num_bytes_written. Num bytes written to zip stream output.

addFile() публичный Метод

add a file to the archive
public addFile ( String $name, String $data, array $opt = [] )
$name String - path of file in archive (including directory). @param String $data - contents of file @param array $opt - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // add a file named 'foo.txt' $data = file_get_contents('foo.txt'); $zip->addFile('foo.txt', $data); // add a file named 'bar.jpg' with a comment and a last-modified // time of two hours ago $data = file_get_contents('bar.jpg'); $zip->addFile('bar.jpg', $data, array( 'time' => time() - 2 * 3600, 'comment' => 'this is a comment about bar.jpg', ));
$data String
$opt array

addFileFromPath() публичный Метод

add a file at path to the archive. Note that large files may be compresed differently than smaller files; see the "Large File Support" section above for more information.
public addFileFromPath ( String $name, String $path, array $opt = [] ) : void
$name String - name of file in archive (including directory path). @param String $path - path to file on disk (note: paths should be encoded using UNIX-style forward slashes -- e.g '/path/to/some/file'). @param array $opt - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // add a file named 'foo.txt' from the local file '/tmp/foo.txt' $zip->addFileFromPath('foo.txt', '/tmp/foo.txt'); // add a file named 'bigfile.rar' from the local file // '/usr/share/bigfile.rar' with a comment and a last-modified // time of two hours ago $path = '/usr/share/bigfile.rar'; $zip->addFileFromPath('bigfile.rar', $path, array( 'time' => time() - 2 * 3600, 'comment' => 'this is a comment about bar.jpg', ));
$path String
$opt array
Результат void

addFileFromStream() публичный Метод

dds an open stream to the archive uncompressed
public addFileFromStream ( String $name, Resource $stream, array $opt = [] ) : void
$name String - path of file in archive (including directory).
$stream Resource - contents of file as a stream resource
$opt array - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // create a temporary file stream and write text to it $fp = tmpfile(); fwrite($fp, 'The quick brown fox jumped over the lazy dog.'); // add a file named 'streamfile.txt' from the content of the stream $x->addFile_from_stream('streamfile.txt', $fp);
Результат void

addFileHeader() защищенный Метод

Create and send zip header for this file.
protected addFileHeader ( String $name, Array &$opt, integer $meth, string $crc, integer $zlen, integer $len, Hex $genb ) : integer
$name String
$opt Array
$meth integer
$crc string
$zlen integer
$len integer
$genb Hex
Результат integer $num_bytes_written

addLargeFile() защищенный Метод

Add a large file from the given path.
protected addLargeFile ( String $name, String $path, array $opt = [] ) : void
$name String
$path String
$opt array
Результат void

clear() защищенный Метод

Clear all internal variables. Note that the stream object is not usable after this.
protected clear ( ) : void
Результат void

dostime() закрытый защищенный Метод

Convert a UNIX timestamp to a DOS timestamp.
final protected dostime ( integer $when ) : integer
$when integer
Результат integer DOS Timestamp

finish() публичный Метод

Write zip footer to stream. Example: add a list of files to the archive $files = array('foo.txt', 'bar.jpg'); foreach ($files as $path) $zip->addFile($path, file_get_contents($path)); write footer to stream $zip->finish();
public finish ( ) : void
Результат void

isLargeFile() защищенный Метод

Is this file larger than large_file_size?
protected isLargeFile ( string $path ) : boolean
$path string
Результат boolean

packFields() защищенный Метод

Create a format string and argument list for pack(), then call pack() and return the result.
protected packFields ( array $fields ) : string
$fields array
Результат string

send() защищенный Метод

Send string, sending HTTP headers if necessary.
protected send ( String $str ) : void
$str String
Результат void

sendHttpHeaders() защищенный Метод

Send HTTP headers for this stream.
protected sendHttpHeaders ( ) : void
Результат void

Описание свойств

$cdr_ofs публичное свойство

public int $cdr_ofs
Результат integer

$files публичное свойство

public array $files
Результат array

$need_headers защищенное свойство

protected bool $need_headers
Результат boolean

$ofs публичное свойство

public int $ofs
Результат integer

$opt публичное свойство

Global Options
public array $opt
Результат array

$output_name защищенное свойство

protected null|String $output_name
Результат null | String