MediaWiki master
ZipDirectoryReader Class Reference

A class for reading ZIP file directories, for the purposes of upload verification. More...

Static Public Member Functions

static read ( $fileName, $callback, $options=[])
 Read a ZIP file and call a function for each file discovered in it.
 
static readHandle ( $file, $callback, $options=[])
 Read an opened file handle presumed to be a ZIP and call a function for each file discovered in it.
 

Protected Member Functions

 __construct ( $file, $callback, $options)
 

Protected Attributes

 $buffer
 A segmented cache of the file contents.
 
 $callback
 The file data callback.
 
 $data
 
 $eocdr
 Stored headers.
 
 $eocdr64
 
 $eocdr64Locator
 
 $file
 The opened file resource.
 
 $fileLength
 The cached length of the file, or null if it has not been loaded yet.
 
 $zip64 = false
 The ZIP64 mode.
 

Detailed Description

A class for reading ZIP file directories, for the purposes of upload verification.

Only a functional interface is provided: ZipFileReader::read(). No access is given to object instances.

Definition at line 32 of file ZipDirectoryReader.php.

Constructor & Destructor Documentation

◆ __construct()

ZipDirectoryReader::__construct ( $file,
$callback,
$options )
protected
Parameters
resource$file
callable$callback
array$options

Definition at line 149 of file ZipDirectoryReader.php.

References $callback, and $file.

Member Function Documentation

◆ read()

static ZipDirectoryReader::read ( $fileName,
$callback,
$options = [] )
static

Read a ZIP file and call a function for each file discovered in it.

Because this class is aimed at verification, an error is raised on suspicious or ambiguous input, instead of emulating some standard behavior.

Parameters
string$fileNameThe archive file name
callable$callbackThe callback function. It will be called for each file with a single associative array each time, with members:
  • name: The file name. Directories conventionally have a trailing slash.
  • mtime: The file modification time, in MediaWiki 14-char format
  • size: The uncompressed file size
Parameters
array$optionsAn associative array of read options, with the option name in the key. This may currently contain:
  • zip64: If this is set to true, then we will emulate a library with ZIP64 support, like OpenJDK 7. If it is set to false, then we will emulate a library with no knowledge of ZIP64.

    NOTE: The ZIP64 code is untested and probably doesn't work. It turned out to be easier to just reject ZIP64 archive uploads, since they are likely to be very rare. Confirming safety of a ZIP64 file is fairly complex. What do you do with a file that is ambiguous and broken when read with a non-ZIP64 reader, but valid when read with a ZIP64 reader? This situation is normal for a valid ZIP64 file, and working out what non-ZIP64 readers will make of such a file is not trivial.

Returns
Status A Status object. The following fatal errors are defined:
 - zip-file-open-error: The file could not be opened.

 - zip-wrong-format: The file does not appear to be a ZIP file.

 - zip-bad: There was something wrong or ambiguous about the file
   data.

 - zip-unsupported: The ZIP file uses features which
   ZipDirectoryReader does not support.
The default messages for those fatal errors are written in a way that makes sense for upload verification.

If a fatal error is returned, more information about the error will be available in the debug log.

Note that the callback function may be called any number of times before a fatal error is returned. If this occurs, the data sent to the callback function should be discarded.

Definition at line 90 of file ZipDirectoryReader.php.

References $callback, and $file.

◆ readHandle()

static ZipDirectoryReader::readHandle ( $file,
$callback,
$options = [] )
static

Read an opened file handle presumed to be a ZIP and call a function for each file discovered in it.

See also
ZipDirectoryReader::read
Parameters
resource$fileA seekable stream containing the archive
callable$callback
array$options
Returns
Status

Definition at line 107 of file ZipDirectoryReader.php.

References $callback, and $file.

Member Data Documentation

◆ $buffer

ZipDirectoryReader::$buffer
protected

A segmented cache of the file contents.

Definition at line 119 of file ZipDirectoryReader.php.

◆ $callback

ZipDirectoryReader::$callback
protected

The file data callback.

Definition at line 122 of file ZipDirectoryReader.php.

Referenced by __construct(), read(), and readHandle().

◆ $data

ZipDirectoryReader::$data
protected

Definition at line 130 of file ZipDirectoryReader.php.

◆ $eocdr

ZipDirectoryReader::$eocdr
protected

Stored headers.

Definition at line 128 of file ZipDirectoryReader.php.

◆ $eocdr64

ZipDirectoryReader::$eocdr64
protected

Definition at line 128 of file ZipDirectoryReader.php.

◆ $eocdr64Locator

ZipDirectoryReader::$eocdr64Locator
protected

Definition at line 128 of file ZipDirectoryReader.php.

◆ $file

ZipDirectoryReader::$file
protected

The opened file resource.

Definition at line 113 of file ZipDirectoryReader.php.

Referenced by __construct(), read(), and readHandle().

◆ $fileLength

ZipDirectoryReader::$fileLength
protected

The cached length of the file, or null if it has not been loaded yet.

Definition at line 116 of file ZipDirectoryReader.php.

◆ $zip64

ZipDirectoryReader::$zip64 = false
protected

The ZIP64 mode.

Definition at line 125 of file ZipDirectoryReader.php.


The documentation for this class was generated from the following file: