Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 602 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ZipStream:: (15 methods):
  __construct()
  addFile()
  addFileFromPath()
  addFileFromStream()
  addFileFromPsr7Stream()
  finish()
  addCdr64Eof()
  packFields()
  send()
  sendHttpHeaders()
  addCdr64Locator()
  addCdrEof()
  clear()
  isLargeFile()
  addToCdr()


Class: ZipStream  - X-Ref

ZipStream

Streamed, dynamically generated zip archives.

Usage:

Streaming zip archives is a simple, three-step process:

1.  Create the zip stream:

$zip = new ZipStream('example.zip');

2.  Add one or more files to the archive:

* add first file
$data = file_get_contents('some_file.gif');
$zip->addFile('some_file.gif', $data);

* add second file
$data = file_get_contents('some_file.gif');
$zip->addFile('another_file.png', $data);

3.  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();
__construct(?string $name = null, ?ArchiveOptions $opt = null)   X-Ref
Create a new ZipStream object.

Parameters:

param: String $name - Name of output file (optional).
param: ArchiveOptions $opt - Archive Options

addFile(string $name, string $data, ?FileOptions $options = null)   X-Ref
addFile

Add a file to the archive.

param: String $name - path of file in archive (including directory).
param: String $data - contents of file
param: FileOptions $options

addFileFromPath(string $name, string $path, ?FileOptions $options = null)   X-Ref
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.

param: String $name - name of file in archive (including directory path).
param: String $path - path to file on disk (note: paths should be encoded using
param: FileOptions $options
return: void

addFileFromStream(string $name, $stream, ?FileOptions $options = null)   X-Ref
addFileFromStream

Add an open stream to the archive.

param: String $name - path of file in archive (including directory).
param: resource $stream - contents of file as a stream resource
param: FileOptions $options
return: void

addFileFromPsr7Stream(string $name,StreamInterface $stream,?FileOptions $options = null)   X-Ref
addFileFromPsr7Stream

Add an open stream to the archive.

param: String $name - path of file in archive (including directory).
param: StreamInterface $stream - contents of file as a stream resource
param: FileOptions $options
return: void

finish()   X-Ref
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();
return: void

addCdr64Eof()   X-Ref
Send ZIP64 CDR EOF (Central Directory Record End-of-File) record.

return: void

packFields(array $fields)   X-Ref
Create a format string and argument list for pack(), then call
pack() and return the result.

param: array $fields
return: string

send(string $str)   X-Ref
Send string, sending HTTP headers if necessary.
Flush output after write if configure option is set.

param: String $str
return: void

sendHttpHeaders()   X-Ref
Send HTTP headers for this stream.

return: void

addCdr64Locator()   X-Ref
Send ZIP64 CDR Locator (Central Directory Record Locator) record.

return: void

addCdrEof()   X-Ref
Send CDR EOF (Central Directory Record End-of-File) record.

return: void

clear()   X-Ref
Clear all internal variables. Note that the stream object is not
usable after this.

return: void

isLargeFile(string $path)   X-Ref
Is this file larger than large_file_size?

param: string $path
return: bool

addToCdr(File $file)   X-Ref
Save file attributes for trailing CDR record.

param: File $file
return: void