MediaWiki master
Wikimedia\Mime\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

string[] $buffer
 A segmented cache of the file contents.
 
callable $callback
 The file data callback.
 
array $eocdr
 Stored headers.
 
array $eocdr64
 Stored headers.
 
array $eocdr64Locator
 Stored headers.
 
resource $file
 The opened file resource.
 
int null $fileLength
 The cached length of the file, or null if it has not been loaded yet.
 
bool $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 35 of file ZipDirectoryReader.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 155 of file ZipDirectoryReader.php.

References Wikimedia\Mime\ZipDirectoryReader\$callback, and Wikimedia\Mime\ZipDirectoryReader\$file.

Member Function Documentation

◆ read()

static Wikimedia\Mime\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
StatusValue A StatusValue 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 94 of file ZipDirectoryReader.php.

References Wikimedia\Mime\ZipDirectoryReader\$callback, and Wikimedia\Mime\ZipDirectoryReader\$file.

◆ readHandle()

static Wikimedia\Mime\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
StatusValue

Definition at line 111 of file ZipDirectoryReader.php.

References Wikimedia\Mime\ZipDirectoryReader\$callback, and Wikimedia\Mime\ZipDirectoryReader\$file.

Member Data Documentation

◆ $buffer

string [] Wikimedia\Mime\ZipDirectoryReader::$buffer
protected

A segmented cache of the file contents.

Definition at line 123 of file ZipDirectoryReader.php.

◆ $callback

callable Wikimedia\Mime\ZipDirectoryReader::$callback
protected

◆ $eocdr

array Wikimedia\Mime\ZipDirectoryReader::$eocdr
protected

Stored headers.

Definition at line 132 of file ZipDirectoryReader.php.

◆ $eocdr64

array Wikimedia\Mime\ZipDirectoryReader::$eocdr64
protected

Stored headers.

Definition at line 134 of file ZipDirectoryReader.php.

◆ $eocdr64Locator

array Wikimedia\Mime\ZipDirectoryReader::$eocdr64Locator
protected

Stored headers.

Definition at line 136 of file ZipDirectoryReader.php.

◆ $file

resource Wikimedia\Mime\ZipDirectoryReader::$file
protected

◆ $fileLength

int null Wikimedia\Mime\ZipDirectoryReader::$fileLength
protected

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

Definition at line 120 of file ZipDirectoryReader.php.

◆ $zip64

bool Wikimedia\Mime\ZipDirectoryReader::$zip64 = false
protected

The ZIP64 mode.

Definition at line 129 of file ZipDirectoryReader.php.


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