Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
zip_archive Class Reference
Inheritance diagram for zip_archive:
file_archive

Public Member Functions

 __construct ()
 Create new zip_archive instance.
 
 add_directory ($localname)
 Add empty directory into archive. More...
 
 add_file_from_pathname ($localname, $pathname)
 Add file into archive. More...
 
 add_file_from_string ($localname, $contents)
 Add content of string into archive. More...
 
 close ()
 Close archive, write changes to disk. More...
 
 count ()
 Returns number of files in archive. More...
 
 current ()
 Returns current file info. More...
 
 estimated_count ()
 Returns approximate number of files in archive. More...
 
 extract_to ($destination, $index)
 Extract the archive contents to the given location. More...
 
 get_info ($index)
 Returns file information. More...
 
 get_stream ($index)
 Returns file stream for reading of content. More...
 
 is_system_file ($fileinfo)
 
 key ()
 Returns the index of current file. More...
 
 list_files ()
 Returns array of info about all files in archive. More...
 
 next ()
 Moves forward to next file.
 
 open ($archivepathname, $mode=file_archive::CREATE, $encoding=null)
 Open or create archive (depending on $mode). More...
 
 rewind ()
 Rewinds back to the first file.
 
 valid ()
 Did we reach the end? More...
 

Static Public Member Functions

static zip_get_central_end ($fp, $filesize)
 Read end of central signature of ZIP file.
 
static zip_parse_file_header ($data, $centralend, &$pos)
 Parse file header.
 

Public Attributes

const CREATE = 2
 Open archive if exists, create if does not.
 
const OPEN = 1
 Open archive if exists, fail if does not exist.
 
const OVERWRITE = 4
 Always create new archive.
 

Protected Member Functions

 fix_utf8_flags ()
 Add unicode flag to all files in archive. More...
 
 init_namelookup ()
 Create a map of file names used in zip archive. More...
 
 mangle_pathname ($localname)
 Normalize $localname, always keep in utf-8 encoding. More...
 
 unmangle_pathname ($localname)
 Tries to convert $localname into utf-8 please note that it may fail really badly. More...
 

Protected Attributes

string $archivepathname = null
 Pathname of archive.
 
bool $emptyziphack = false
 ugly hack for broken empty zip handling in < PHP 5.3.10
 
string $encoding = 'utf-8'
 Encoding of file names - windows usually expects DOS single-byte charset.
 
int $mode = null
 archive open mode
 
bool $modified = false
 was this archive modified?
 
array $namelookup = null
 unicode decoding array, created by decoding zip file
 
int $pos = 0
 Iteration position.
 
int $usedmem = 0
 Used memory tracking.
 
ZipArchive $za
 instance
 

Static Protected Attributes

static string $emptyzipcontent = 'UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA=='
 base64 encoded contents of empty zip file
 

Member Function Documentation

◆ add_directory()

zip_archive::add_directory (   $localname)

Add empty directory into archive.

Parameters
string$localnamename of file in archive
Return values
boolsuccess

Reimplemented from file_archive.

◆ add_file_from_pathname()

zip_archive::add_file_from_pathname (   $localname,
  $pathname 
)

Add file into archive.

Parameters
string$localnamename of file in archive
string$pathnamelocation of file
Return values
boolsuccess

Reimplemented from file_archive.

◆ add_file_from_string()

zip_archive::add_file_from_string (   $localname,
  $contents 
)

Add content of string into archive.

Parameters
string$localnamename of file in archive
string$contentscontents
Return values
boolsuccess

Reimplemented from file_archive.

◆ close()

zip_archive::close ( )

Close archive, write changes to disk.

Return values
boolsuccess

Reimplemented from file_archive.

◆ count()

zip_archive::count ( )

Returns number of files in archive.

Return values
intnumber of files

Reimplemented from file_archive.

◆ current()

zip_archive::current ( )

Returns current file info.

Return values
stdClass

◆ estimated_count()

zip_archive::estimated_count ( )

Returns approximate number of files in archive.

This may be a slight overestimate.

Return values
int|boolEstimated number of files, or false if not opened

◆ extract_to()

zip_archive::extract_to (   $destination,
  $index 
)

Extract the archive contents to the given location.

Parameters
string$destinationPath to the location where to extract the files.
int$indexIndex of the archive entry.
Return values
booltrue on success or false on failure

◆ fix_utf8_flags()

zip_archive::fix_utf8_flags ( )
protected

Add unicode flag to all files in archive.

NOTE: single disk archives only, no ZIP64 support.

Return values
boolsuccess, modifies the file contents

◆ get_info()

zip_archive::get_info (   $index)

Returns file information.

Parameters
int$indexindex of file
Return values
stdClass|boolinfo object or false if error

Reimplemented from file_archive.

◆ get_stream()

zip_archive::get_stream (   $index)

Returns file stream for reading of content.

Parameters
int$indexindex of file
Return values
resource|boolfile handle or false if error

Reimplemented from file_archive.

◆ init_namelookup()

zip_archive::init_namelookup ( )
protected

Create a map of file names used in zip archive.

Return values
void

◆ key()

zip_archive::key ( )

Returns the index of current file.

Return values
intcurrent file index

◆ list_files()

zip_archive::list_files ( )

Returns array of info about all files in archive.

Return values
arrayof file infos

Reimplemented from file_archive.

◆ mangle_pathname()

zip_archive::mangle_pathname (   $localname)
protected

Normalize $localname, always keep in utf-8 encoding.

Parameters
string$localnamename of file in utf-8 encoding
Return values
stringnormalised compressed file or directory name

Reimplemented from file_archive.

◆ open()

zip_archive::open (   $archivepathname,
  $mode = file_archive::CREATE,
  $encoding = null 
)

Open or create archive (depending on $mode).

Todo:
MDL-31048 return error message
Parameters
string$archivepathname
int$modeOPEN, CREATE or OVERWRITE constant
string$encodingarchive local paths encoding, empty means autodetect
Return values
boolsuccess

Reimplemented from file_archive.

◆ unmangle_pathname()

zip_archive::unmangle_pathname (   $localname)
protected

Tries to convert $localname into utf-8 please note that it may fail really badly.

The resulting file name is cleaned.

Parameters
string$localnamename (encoding is read from zip file or guessed)
Return values
stringin utf-8

Reimplemented from file_archive.

◆ valid()

zip_archive::valid ( )

Did we reach the end?

Return values
bool

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