ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
Public Member Functions | |
__construct (?string $name=null, ?ArchiveOptions $opt=null) | |
Create a new ZipStream object. More... | |
addFile (string $name, string $data, ?FileOptions $options=null) | |
addFile More... | |
addFileFromPath (string $name, string $path, ?FileOptions $options=null) | |
addFileFromPath More... | |
addFileFromStream (string $name, $stream, ?FileOptions $options=null) | |
addFileFromStream More... | |
addFileFromPsr7Stream (string $name, StreamInterface $stream, ?FileOptions $options=null) | |
addFileFromPsr7Stream More... | |
finish () | |
finish More... | |
send (string $str) | |
Send string, sending HTTP headers if necessary. More... | |
isLargeFile (string $path) | |
Is this file larger than large_file_size? More... | |
addToCdr (File $file) | |
Save file attributes for trailing CDR record. More... | |
Static Public Member Functions | |
static | packFields (array $fields) |
Create a format string and argument list for pack(), then call pack() and return the result. More... | |
Data Fields | |
const | ZIP_VERSION_MADE_BY = 0x603 |
This number corresponds to the ZIP version/OS used (2 bytes) From: https://www.iana.org/assignments/media-types/application/zip The upper byte (leftmost one) indicates the host system (OS) for the file. More... | |
const | FILE_HEADER_SIGNATURE = 0x04034b50 |
The following signatures end with 0x4b50, which in ASCII is PK, the initials of the inventor Phil Katz. More... | |
const | CDR_FILE_SIGNATURE = 0x02014b50 |
const | CDR_EOF_SIGNATURE = 0x06054b50 |
const | DATA_DESCRIPTOR_SIGNATURE = 0x08074b50 |
const | ZIP64_CDR_EOF_SIGNATURE = 0x06064b50 |
const | ZIP64_CDR_LOCATOR_SIGNATURE = 0x07064b50 |
$opt | |
$files = [] | |
$cdr_ofs | |
$ofs | |
Protected Member Functions | |
addCdr64Eof () | |
Send ZIP64 CDR EOF (Central Directory Record End-of-File) record. More... | |
sendHttpHeaders () | |
Send HTTP headers for this stream. More... | |
addCdr64Locator () | |
Send ZIP64 CDR Locator (Central Directory Record Locator) record. More... | |
addCdrEof () | |
Send CDR EOF (Central Directory Record End-of-File) record. More... | |
clear () | |
Clear all internal variables. More... | |
Protected Attributes | |
$need_headers | |
$output_name | |
Streamed, dynamically generated zip archives.
Usage:
Streaming zip archives is a simple, three-step process:
Create the zip stream:
$zip = new ZipStream('example.zip');
Finish the zip stream:
$zip->finish();
You can also add an archive comment, add comments to individual files, and adjust the timestamp of files. See the API documentation for each method below for additional information.
Example:
// create a new zip stream object $zip = new ZipStream('some_files.zip');
// list of local files $files = array('foo.txt', 'bar.jpg');
// read and add each file to the archive foreach ($files as $path) $zip->addFile($path, file_get_contents($path));
// write archive footer to stream $zip->finish();
Definition at line 58 of file ZipStream.php.
ZipStream\ZipStream::__construct | ( | ?string | $name = null , |
?ArchiveOptions | $opt = null |
||
) |
Create a new ZipStream object.
Parameters:
String | $name | - Name of output file (optional). |
ArchiveOptions | $opt | - Archive Options |
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 largeFile* options above, with the following caveats:
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 $opt->setComment = 'this is a comment for the zip file.'; $zip = new ZipStream('bar.zip', $opt);
Notes:
In order to let this library send HTTP headers, a filename must be given and the option sendHttpHeaders
must be true
. This behavior is to allow software to send its own headers (including the filename), and still use this library.
Definition at line 171 of file ZipStream.php.
References $name.
|
protected |
Send ZIP64 CDR EOF (Central Directory Record End-of-File) record.
Definition at line 386 of file ZipStream.php.
References $ret, and ZipStream\Option\Version\ZIP64.
|
protected |
Send ZIP64 CDR Locator (Central Directory Record Locator) record.
Definition at line 514 of file ZipStream.php.
References $ret.
|
protected |
Send CDR EOF (Central Directory Record End-of-File) record.
Definition at line 534 of file ZipStream.php.
References $comment, and $ret.
ZipStream\ZipStream::addFile | ( | string | $name, |
string | $data, | ||
?FileOptions | $options = null |
||
) |
addFile
Add a file to the archive.
String | $name | - path of file in archive (including directory). |
String | $data | - contents of file |
FileOptions | $options | File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. method - Storage method for file ("store" or "deflate") |
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'); $opt->setTime = time() - 2 * 3600; $opt->setComment = 'this is a comment about bar.jpg'; $zip->addFile('bar.jpg', $data, $opt);
Definition at line 210 of file ZipStream.php.
References PHPMailer\PHPMailer\$options.
ZipStream\ZipStream::addFileFromPath | ( | string | $name, |
string | $path, | ||
?FileOptions | $options = null |
||
) |
addFileFromPath
Add a file at path to the archive.
Note that large files may be compressed differently than smaller files; see the "Large File Support" section above for more information.
String | $name | - name of file in archive (including directory path). |
String | $path | - path to file on disk (note: paths should be encoded using UNIX-style forward slashes – e.g '/path/to/some/file'). |
FileOptions | $options | File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. method - Storage method for file ("store" or "deflate") |
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'; $opt->setTime = time() - 2 * 3600; $opt->setComment = 'this is a comment about bar.jpg'; $zip->addFileFromPath('bigfile.rar', $path, $opt);
Definition at line 256 of file ZipStream.php.
References PHPMailer\PHPMailer\$options.
ZipStream\ZipStream::addFileFromPsr7Stream | ( | string | $name, |
StreamInterface | $stream, | ||
?FileOptions | $options = null |
||
) |
addFileFromPsr7Stream
Add an open stream to the archive.
String | $name | - path of file in archive (including directory). |
StreamInterface | $stream | - contents of file as a stream resource |
FileOptions | $options | 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->addFileFromPsr7Stream('streamfile.txt', $fp);
Definition at line 324 of file ZipStream.php.
References PHPMailer\PHPMailer\$options.
ZipStream\ZipStream::addFileFromStream | ( | string | $name, |
$stream, | |||
?FileOptions | $options = null |
||
) |
addFileFromStream
Add an open stream to the archive.
String | $name | - path of file in archive (including directory). |
resource | $stream | - contents of file as a stream resource |
FileOptions | $options | 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->addFileFromStream('streamfile.txt', $fp);
Definition at line 290 of file ZipStream.php.
References PHPMailer\PHPMailer\$options, and GuzzleHttp\Psr7\$stream.
ZipStream\ZipStream::addToCdr | ( | File | $file | ) |
Save file attributes for trailing CDR record.
File | $file |
Definition at line 593 of file ZipStream.php.
References ZipStream\File\getCdrFile(), and ZipStream\File\getTotalLength().
|
protected |
Clear all internal variables.
Note that the stream object is not usable after this.
Definition at line 564 of file ZipStream.php.
ZipStream\ZipStream::finish | ( | ) |
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();
OverflowException |
Definition at line 354 of file ZipStream.php.
References ZipStream\Bigint\init().
ZipStream\ZipStream::isLargeFile | ( | string | $path | ) |
Is this file larger than large_file_size?
string | $path |
Definition at line 578 of file ZipStream.php.
|
static |
Create a format string and argument list for pack(), then call pack() and return the result.
array | $fields |
Definition at line 416 of file ZipStream.php.
References $format.
ZipStream\ZipStream::send | ( | string | $str | ) |
Send string, sending HTTP headers if necessary.
Flush output after write if configure option is set.
String | $str |
Definition at line 455 of file ZipStream.php.
|
protected |
Send HTTP headers for this stream.
Definition at line 481 of file ZipStream.php.
References $key.
ZipStream\ZipStream::$cdr_ofs |
Definition at line 112 of file ZipStream.php.
ZipStream\ZipStream::$files = [] |
Definition at line 107 of file ZipStream.php.
|
protected |
Definition at line 122 of file ZipStream.php.
ZipStream\ZipStream::$ofs |
Definition at line 117 of file ZipStream.php.
ZipStream\ZipStream::$opt |
Definition at line 102 of file ZipStream.php.
|
protected |
Definition at line 127 of file ZipStream.php.
const ZipStream\ZipStream::CDR_EOF_SIGNATURE = 0x06054b50 |
Definition at line 92 of file ZipStream.php.
const ZipStream\ZipStream::CDR_FILE_SIGNATURE = 0x02014b50 |
Definition at line 91 of file ZipStream.php.
const ZipStream\ZipStream::DATA_DESCRIPTOR_SIGNATURE = 0x08074b50 |
Definition at line 93 of file ZipStream.php.
const ZipStream\ZipStream::FILE_HEADER_SIGNATURE = 0x04034b50 |
The following signatures end with 0x4b50, which in ASCII is PK, the initials of the inventor Phil Katz.
See https://en.wikipedia.org/wiki/Zip_(file_format)#File_headers
Definition at line 90 of file ZipStream.php.
const ZipStream\ZipStream::ZIP64_CDR_EOF_SIGNATURE = 0x06064b50 |
Definition at line 94 of file ZipStream.php.
const ZipStream\ZipStream::ZIP64_CDR_LOCATOR_SIGNATURE = 0x07064b50 |
Definition at line 95 of file ZipStream.php.
const ZipStream\ZipStream::ZIP_VERSION_MADE_BY = 0x603 |
This number corresponds to the ZIP version/OS used (2 bytes) From: https://www.iana.org/assignments/media-types/application/zip The upper byte (leftmost one) indicates the host system (OS) for the file.
Software can use this information to determine the line record format for text files etc. The current mappings are:
0 - MS-DOS and OS/2 (F.A.T. file systems) 1 - Amiga 2 - VAX/VMS 3 - *nix 4 - VM/CMS 5 - Atari ST 6 - OS/2 H.P.F.S. 7 - Macintosh 8 - Z-System 9 - CP/M 10 thru 255 - unused
The lower byte (rightmost one) indicates the version number of the software used to encode the file. The value/10 indicates the major version number, and the value mod 10 is the minor version number. Here we are using 6 for the OS, indicating OS/2 H.P.F.S. to prevent file permissions issues upon extract (see #84) 0x603 is 00000110 00000011 in binary, so 6 and 3
Definition at line 83 of file ZipStream.php.