Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
tgz_extractor Class Reference

Extracts .tar.gz files (POSIX format). More...

Public Member Functions

 __construct ($archivefile)
 Constructor.
 
 extract (tgz_extractor_handler $handler, file_progress $progress=null)
 Extracts the archive.
 
 list_files ()
 Lists files in the archive, either using the index file (if present), or by basically extracting the whole thing if there isn't an index file.
 

Public Attributes

int const MODE_EXTRACT = 0
 If extracting (default).
 
int const MODE_LIST = 1
 Listing contents.
 
int const MODE_LIST_COMPLETE = 2
 Listing contents; list now complete.
 
int const READ_BLOCK_SIZE = 65536
 When reading data, the system reads blocks of this size.
 
int const WRITE_BLOCK_SIZE = 65536
 When writing data, the system writes blocks of this size.
 

Protected Member Functions

 close_current_file ($handler)
 Closes the current file, calls handler, and sets up data.
 
 extract_or_list (tgz_extractor_handler $handler=null, file_progress $progress=null)
 Extracts or lists the archive depending on $this->listmode.
 
 process_file_block ($block, tgz_extractor_handler $handler=null)
 Processes one 512-byte block of an existing file.
 
 process_header ($block, $handler)
 Process 512-byte header block.
 
 start_current_file ($archivepath, $filesize, $mtime, tgz_extractor_handler $handler=null)
 Starts processing a file from archive.
 

Protected Attributes

string $currentarchivepath
 Current file path within archive.
 
string $currentfile
 Full path to current file.
 
int $currentfileprocessed
 Number of bytes of current file already written into buffer.
 
int $currentfilesize
 Size of current file in bytes.
 
resource $currentfp
 File handle to current file.
 
int $currentmtime
 Modified time of current file.
 
int $donefiles
 Number of files processed so far.
 
string $filebuffer
 Buffer containing file data awaiting write.
 
int $filebufferlength
 Current length of buffer in bytes.
 
array $listresults = null
 In list mode, content of the list; outside list mode, null.
 
int $mode = self::MODE_EXTRACT
 Whether listing or extracting.
 
int $numfiles
 Number of files (-1 if not known).
 
string $ospath
 OS path for archive.
 
array $results
 Results array of all files processed.
 
stored_file $storedfile
 File object for archive.
 

Detailed Description

Extracts .tar.gz files (POSIX format).

Constructor & Destructor Documentation

◆ __construct()

tgz_extractor::__construct ( $archivefile)

Constructor.

Parameters
stored_file | string$archivefileMoodle file or OS path to archive

Member Function Documentation

◆ close_current_file()

tgz_extractor::close_current_file ( $handler)
protected

Closes the current file, calls handler, and sets up data.

Parameters
tgz_extractor_handler$handlerWill be called for extracted files
Exceptions
moodle_exceptionIf there is an error closing it

◆ extract()

tgz_extractor::extract ( tgz_extractor_handler $handler,
file_progress $progress = null )

Extracts the archive.

Parameters
tgz_extractor_handler$handlerWill be called for extracted files
file_progress$progressOptional progress reporting
Return values
arrayArray from archive path => true of processed files
Exceptions
moodle_exceptionIf there is any error processing the archive

◆ extract_or_list()

tgz_extractor::extract_or_list ( tgz_extractor_handler $handler = null,
file_progress $progress = null )
protected

Extracts or lists the archive depending on $this->listmode.

Parameters
tgz_extractor_handler$handlerOptional handler
file_progress$progressOptional progress reporting
Exceptions
moodle_exceptionIf there is any error processing the archive

◆ list_files()

tgz_extractor::list_files ( )

Lists files in the archive, either using the index file (if present), or by basically extracting the whole thing if there isn't an index file.

Return values
arrayArray of file listing results:

◆ process_file_block()

tgz_extractor::process_file_block ( $block,
tgz_extractor_handler $handler = null )
protected

Processes one 512-byte block of an existing file.

Parameters
string$blockData block
tgz_extractor_handler$handlerWill be called for extracted files

◆ process_header()

tgz_extractor::process_header ( $block,
$handler )
protected

Process 512-byte header block.

Parameters
string$blockTar block
tgz_extractor_handler$handlerWill be called for extracted files

◆ start_current_file()

tgz_extractor::start_current_file ( $archivepath,
$filesize,
$mtime,
tgz_extractor_handler $handler = null )
protected

Starts processing a file from archive.

Parameters
string$archivepathPath inside archive
int$filesizeSize in bytes
int$mtimeFile-modified time
tgz_extractor_handler$handlerWill be called for extracted files
Exceptions
moodle_exception

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