AR archive file handling
Opening, reading and creating AR archives (like .deb files) in PHP, (*1)
Usage
Reading
Create a reader object:, (*2)
$ar = \Tsg\Ar\Reader::open('/path/to/file');
Get a list of files inside archive:, (*3)
$list = $ar->ls();
This returns an array of files in format:, (*4)
$list = [ 'filename' => [ 'fpos' => position in file, 'size' => size in bytes, 'uid' => user ID, 'gid' => group ID, 'mode' => file mode ] , ... ];
Retrieve a file's contents from inside archive:, (*5)
$data = $ar->get('filename');
This returns the data read directly from the file as found in the ls() method above. You can directly write this data to disk using fwrite() or file_put_contents(), (*6)
Writing
Create a writer object:, (*7)
$ar = \Tsg\Ar\Writer::create('/path/to/file');
Add a file to it:, (*8)
$ar->add('/path/to/file');
Or add multiple files at once using a glob:, (*9)
$ar->add('/path/to/files/*');
Or chain add files!, (*10)
$ar->add('1.file')->add('2.file')->add('3.file');
Then close the file, (*11)
$ar->close();
After the file is closed, it is ready to be used as a standard ar archive. You can confirm it's been written using the ar tool., (*12)