Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Public Member Functions | |
__construct (private OperationMode $operationMode=OperationMode::NORMAL, private readonly string $comment='', $outputStream=null, private readonly CompressionMethod $defaultCompressionMethod=CompressionMethod::DEFLATE, private readonly int $defaultDeflateLevel=6, private readonly bool $enableZip64=true, private readonly bool $defaultEnableZeroHeader=true, private bool $sendHttpHeaders=true, ?Closure $httpHeaderCallback=null, private readonly ?string $outputName=null, private readonly string $contentDisposition='attachment', private readonly string $contentType='application/x-zip', private bool $flushOutput=false,) | |
Create a new ZipStream object. | |
addDirectory (string $fileName, string $comment='', ?DateTimeInterface $lastModificationDateTime=null,) | |
Add a directory to the archive. | |
addFile (string $fileName, string $data, string $comment='', ?CompressionMethod $compressionMethod=null, ?int $deflateLevel=null, ?DateTimeInterface $lastModificationDateTime=null, ?int $maxSize=null, ?int $exactSize=null, ?bool $enableZeroHeader=null,) | |
Add a file to the archive. | |
addFileFromCallback (string $fileName, Closure $callback, string $comment='', ?CompressionMethod $compressionMethod=null, ?int $deflateLevel=null, ?DateTimeInterface $lastModificationDateTime=null, ?int $maxSize=null, ?int $exactSize=null, ?bool $enableZeroHeader=null,) | |
Add a file based on a callback. | |
addFileFromPath (string $fileName, string $path, string $comment='', ?CompressionMethod $compressionMethod=null, ?int $deflateLevel=null, ?DateTimeInterface $lastModificationDateTime=null, ?int $maxSize=null, ?int $exactSize=null, ?bool $enableZeroHeader=null,) | |
Add a file at path to the archive. | |
addFileFromPsr7Stream (string $fileName, StreamInterface $stream, string $comment='', ?CompressionMethod $compressionMethod=null, ?int $deflateLevel=null, ?DateTimeInterface $lastModificationDateTime=null, ?int $maxSize=null, ?int $exactSize=null, ?bool $enableZeroHeader=null,) | |
Add an open stream to the archive. | |
addFileFromStream (string $fileName, $stream, string $comment='', ?CompressionMethod $compressionMethod=null, ?int $deflateLevel=null, ?DateTimeInterface $lastModificationDateTime=null, ?int $maxSize=null, ?int $exactSize=null, ?bool $enableZeroHeader=null,) | |
Add an open stream (resource) to the archive. | |
executeSimulation () | |
Executes a previously calculated simulation. | |
finish () | |
Write zip footer to stream. | |
Public Attributes | |
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. | |
ZipStream\ZipStream::__construct | ( | private OperationMode | $operationMode = OperationMode::NORMAL, |
private readonly string | $comment = '', | ||
$outputStream = null, | |||
private readonly CompressionMethod | $defaultCompressionMethod = CompressionMethod::DEFLATE, | ||
private readonly int | $defaultDeflateLevel = 6, | ||
private readonly bool | $enableZip64 = true, | ||
private readonly bool | $defaultEnableZeroHeader = true, | ||
private bool | $sendHttpHeaders = true, | ||
?Closure | $httpHeaderCallback = null, | ||
private readonly ?string | $outputName = null, | ||
private readonly string | $contentDisposition = 'attachment', | ||
private readonly string | $contentType = 'application/x-zip', | ||
private bool | $flushOutput = false ) |
Create a new ZipStream object.
OperationMode | $operationMode | The mode can be used to switch between NORMAL and SIMULATION_* modes. For details see the OperationMode documentation. |
Default to NORMAL
.
string | $comment | Archive Level Comment |
StreamInterface | resource | null | $outputStream | Override the output of the archive to a different target. |
By default the archive is sent to STDOUT
.
CompressionMethod | $defaultCompressionMethod | How to handle file compression. Legal values are CompressionMethod\DEFLATE (the default), or CompressionMethod\STORE . STORE sends the file raw and is significantly faster, while DEFLATE compresses the file and is much, much slower. |
int | $defaultDeflateLevel | Default deflation level. Only relevant if compressionMethod is DEFLATE . |
See details of deflate_init
bool | $enableZip64 | Enable Zip64 extension, supporting very large archives (any size > 4 GB or file count > 64k) |
bool | $defaultEnableZeroHeader | Enable streaming files with single read. |
When the zero header is set, the file is streamed into the output and the size & checksum are added at the end of the file. This is the fastest method and uses the least memory. Unfortunately not all ZIP clients fully support this and can lead to clients reporting the generated ZIP files as corrupted in combination with other circumstances. (Zip64 enabled, using UTF8 in comments / names etc.)
When the zero header is not set, the length & checksum need to be defined before the file is actually added. To prevent loading all the data into memory, the data has to be read twice. If the data which is added is not seekable, this call will fail.
bool | $sendHttpHeaders | Boolean indicating whether or not to send the HTTP headers for this file. |
?Closure | $httpHeaderCallback | The method called to send HTTP headers |
string | null | $outputName | The name of the created archive. |
Only relevant if $sendHttpHeaders = true
.
string | $contentDisposition | HTTP Content-Disposition |
Only relevant if sendHttpHeaders = true
.
string | $contentType | HTTP Content Type |
Only relevant if sendHttpHeaders = true
.
bool | $flushOutput | Enable flush after every write to output stream. |
self |
ZipStream\ZipStream::addDirectory | ( | string | $fileName, |
string | $comment = '', | ||
?DateTimeInterface | $lastModificationDateTime = null ) |
ZipStream\ZipStream::addFile | ( | string | $fileName, |
string | $data, | ||
string | $comment = '', | ||
?CompressionMethod | $compressionMethod = null, | ||
?int | $deflateLevel = null, | ||
?DateTimeInterface | $lastModificationDateTime = null, | ||
?int | $maxSize = null, | ||
?int | $exactSize = null, | ||
?bool | $enableZeroHeader = null ) |
Add a file to the archive.
See {
string | $data |
contents of file
ZipStream\ZipStream::addFileFromCallback | ( | string | $fileName, |
Closure | $callback, | ||
string | $comment = '', | ||
?CompressionMethod | $compressionMethod = null, | ||
?int | $deflateLevel = null, | ||
?DateTimeInterface | $lastModificationDateTime = null, | ||
?int | $maxSize = null, | ||
?int | $exactSize = null, | ||
?bool | $enableZeroHeader = null ) |
Add a file based on a callback.
This is useful when you want to simulate a lot of files without keeping all of the file handles open at the same time.
string | $fileName | path of file in archive (including directory) |
Closure | $callback | @psalm-param Closure(): (resource|StreamInterface|string) $callback A callback to get the file contents in the shape of a PHP stream, a Psr StreamInterface implementation, or a string. |
string | $comment | ZIP comment for this file |
?CompressionMethod | $compressionMethod | Override defaultCompressionMethod |
See {
?int | $deflateLevel | Override defaultDeflateLevel |
See {
?DateTimeInterface | $lastModificationDateTime | Set last modification time of file. |
Default: now
?int | $maxSize | Only read maxSize bytes from file. |
The file is considered done when either reaching EOF
or the maxSize
.
?int | $exactSize | Read exactly exactSize bytes from file. If EOF is reached before reading exactSize bytes, an error will be thrown. The parameter allows for faster size calculations if the stream does not support fstat size or is slow and otherwise known beforehand. |
?bool | $enableZeroHeader | Override defaultEnableZeroHeader |
See {
ZipStream\ZipStream::addFileFromPath | ( | string | $fileName, |
string | $path, | ||
string | $comment = '', | ||
?CompressionMethod | $compressionMethod = null, | ||
?int | $deflateLevel = null, | ||
?DateTimeInterface | $lastModificationDateTime = null, | ||
?int | $maxSize = null, | ||
?int | $exactSize = null, | ||
?bool | $enableZeroHeader = null ) |
Add a file at path to the archive.
See {
$fileName | name of file in archive (including directory path). |
$path | path to file on disk (note: paths should be encoded using UNIX-style forward slashes – e.g '/path/to/some/file'). |
ZipStream\ZipStream::addFileFromPsr7Stream | ( | string | $fileName, |
StreamInterface | $stream, | ||
string | $comment = '', | ||
?CompressionMethod | $compressionMethod = null, | ||
?int | $deflateLevel = null, | ||
?DateTimeInterface | $lastModificationDateTime = null, | ||
?int | $maxSize = null, | ||
?int | $exactSize = null, | ||
?bool | $enableZeroHeader = null ) |
Add an open stream to the archive.
string | $fileName | path of file in archive (including directory) |
StreamInterface | $stream | contents of file as a stream resource |
string | $comment | ZIP comment for this file |
?CompressionMethod | $compressionMethod | Override defaultCompressionMethod |
See {
?int | $deflateLevel | Override defaultDeflateLevel |
See {
?DateTimeInterface | $lastModificationDateTime | Set last modification time of file. |
Default: now
?int | $maxSize | Only read maxSize bytes from file. |
The file is considered done when either reaching EOF
or the maxSize
.
?int | $exactSize | Read exactly exactSize bytes from file. If EOF is reached before reading exactSize bytes, an error will be thrown. The parameter allows for faster size calculations if the stream does not support fstat size or is slow and otherwise known beforehand. |
?bool | $enableZeroHeader | Override defaultEnableZeroHeader |
See {
ZipStream\ZipStream::addFileFromStream | ( | string | $fileName, |
$stream, | |||
string | $comment = '', | ||
?CompressionMethod | $compressionMethod = null, | ||
?int | $deflateLevel = null, | ||
?DateTimeInterface | $lastModificationDateTime = null, | ||
?int | $maxSize = null, | ||
?int | $exactSize = null, | ||
?bool | $enableZeroHeader = null ) |
Add an open stream (resource) to the archive.
See {
resource | $stream | contents of file as a stream resource |
ZipStream\ZipStream::executeSimulation | ( | ) |
Executes a previously calculated simulation.
ZipStream\ZipStream::finish | ( | ) |
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