Constants

INTERP_LEN

INTERP_LEN

The size of the interp line (fixed size)

VERSION_SIZE

VERSION_SIZE

The size of a version string in the magic block - Up to 12 bytes

OFFSET_SIZE

OFFSET_SIZE

The size of each offset field. As offset are limited to 11 bytes, the theoritical max size of a PHK archive is 100 G bytes. Not tested :)

MAGIC_STRING

MAGIC_STRING

The magic string. This is the string we identify to recognize a PHK archive

MAGIC_STRING_LEN

MAGIC_STRING_LEN

MAGIC_STRING_OFFSET

MAGIC_STRING_OFFSET

INTERP_LEN + 6

MAGIC_LINE_LEN

MAGIC_LINE_LEN

The size of the magic block

AUTOMAP_SECTION

AUTOMAP_SECTION

The name of the optional Automap section, when it exists

CRC_OFFSET

CRC_OFFSET

The offset of the CRC field, from the beginning of the archive file.

The CRC field is 8 bytes long (32 bits in hexadecimal)

Properties

$ftree

$ftree : \PHK\PHK\Virtual\Tree

Type

\PHK\PHK\Virtual\Tree — File tree

$stree

$stree : \PHK\PHK\Virtual\Tree

Type

\PHK\PHK\Virtual\Tree — Section tree

$flags

$flags : integer

Type

integer — Mount flags

$fspace

$fspace : \PHK\PHK\PkgFileSpace

Type

\PHK\PHK\PkgFileSpace — File Handler

$path

$path : string

Type

string — Package path

$magic

$magic : array

Type

array — Magic values

Methods

__construct()

__construct(  $path,   $flags) 

Constructor

This method must be called only from PHK\Mgr::proxy()

Parameters

$path
$flags

Throws

\Exception

crcCheck()

crcCheck() 

insertCrc()

insertCrc(string  $buffer, string  $crc) : string

Inserts or clears a CRC in a memory buffer

Parameters

string $buffer

The original buffer whose CRC will be overwritten

string $crc

If set, the CRC as an 8-char string (in hexadecimal). If not set, we clear the CRC (set it to '00000000').

Returns

string —

The modified buffer

checkCrcBuffer()

checkCrcBuffer(string  $buffer) : void

Checks a memory buffer's CRC

The memory buffer is supposed to contain a whole PHK archive.

No return value: if the CRC check fails, an exception is thrown.

Parameters

string $buffer

Throws

\Exception

fixCrc()

fixCrc(string  $buffer) : string

Computes and inserts a CRC in a memory buffer

Parameters

string $buffer

Returns

string —

The modified buffer

fileIsPackage()

fileIsPackage(string  $path) : boolean

Check if a given path contains a PHK package

Parameters

string $path

path to check (can be virtual)

Returns

boolean

dataIsPackage()

dataIsPackage(string  $data) : boolean

Check if a data buffer contains a PHK package

Parameters

string $data

data buffer to check

Returns

boolean

getMagicValues()

getMagicValues() : array

Extracts the values out of a magic line buffer

Note: A package is signed if (Signature offset != File size)

Returns

array —

An array containing the magic values

magicField()

magicField(  $name) 

Parameters

$name

pathList()

pathList() 

sectionList()

sectionList() 

signed()

signed() : boolean

Is this package digitally signed ?

Returns

boolean

interp()

interp() : string

Gets interpreter string

If the interpreter is defined, returns it. Else, returns an empty string

Throws

\Exception

if the interpreter string is invalid

Returns

string

interpBlock()

interpBlock(string  $interp) : string

Builds an interpreter block from an interpreter string

Note: can be applied to a signed package as the signature ignores the interpreter block and the CRC.

Parameters

string $interp

Interpreter to set or empty string to clear

Returns

string —

Interpreter block (INTERP_LEN). Including trailing '\n'

setBufferInterp()

setBufferInterp(string  $path, string  $interp = '') : string

Inserts a new interpreter block in a file's content

Allows a PHK user to change its interpreter string without having to use the \PHK\Build\Creator kit.

Note: can be applied to a signed package as the signature ignores the interpreter block and the CRC.

Parameters

string $path

PHK archive's path

string $interp

Interpreter string to set (empty to clear)

Returns

string —

The modified buffer (the file is not overwritten)

version()

version() : string

The version of the \PHK\Build\Creator tool this package was created from

Returns

string —

Version

path()

path() : string

Returns the $path property

Returns

string

section()

section(string  $name) : string

Get a section's content

Parameters

string $name

The section name

Throws

\Exception

if section does not exist or cannot be read

Returns

string —

The section's content

ftree()

ftree() 

stree()

stree() 

flags()

flags() : integer

Returns the $flags property

Returns

integer

displayPackages()

displayPackages() 

showfiles()

showfiles() 

getCrc()

getCrc(string  $buffer) : string

Returns the CRC extracted from a memory buffer (not the computed one)

Parameters

string $buffer

Returns

string —

The extracted 8-char hex CRC

computeCrc()

computeCrc(string  $buffer) : string

Computes a CRC from a given memory buffer

As the given buffer already contains a CRC, we first clear it.

Parameters

string $buffer

Returns

string —

The computed 8-char hex CRC

cacheData()

cacheData() : void

Brings all data in memory

After this function has run, we never access the package file any more.

clearCache()

clearCache() : void

Clears the data cache