1PHPArchive - Pure PHP ZIP and TAR handling 2========================================== 3 4This library allows to handle new ZIP and TAR archives without the need for any special PHP extensions (gz and bzip are 5needed for compression). It can create new files or extract existing ones. 6 7To keep things simple, the modification (adding or removing files) of existing archives is not supported. 8 9[](https://travis-ci.org/splitbrain/php-archive) 10 11Install 12------- 13 14Use composer: 15 16```php composer.phar require splitbrain/php-archive``` 17 18Usage 19----- 20 21The usage for the Zip and Tar classes are basically the same. Here are some 22examples for working with TARs to get you started. Check the source code 23comments for more info 24 25```php 26require_once 'vendor/autoload.php'; 27use splitbrain\PHPArchive\Tar; 28 29// To list the contents of an existing TAR archive, open() it and use 30// contents() on it: 31$tar = new Tar(); 32$tar->open('myfile.tgz'); 33$toc = $tar->contents(); 34print_r($toc); // array of FileInfo objects 35 36// To extract the contents of an existing TAR archive, open() it and use 37// extract() on it: 38$tar = new Tar(); 39$tar->open('myfile.tgz'); 40$tar->extract('/tmp'); 41 42// To create a new TAR archive directly on the filesystem (low memory 43// requirements), create() it: 44$tar = new Tar(); 45$tar->create('myfile.tgz'); 46$tar->addFile(...); 47$tar->addData(...); 48... 49$tar->close(); 50 51// To create a TAR archive directly in memory, create() it, add*() 52// files and then either save() or getArchive() it: 53$tar = new Tar(); 54$tar->create(); 55$tar->addFile(...); 56$tar->addData(...); 57... 58$tar->save('myfile.tgz'); // compresses and saves it 59echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it 60``` 61 62Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore 63you can call ```setCompression``` before each ```addFile()``` and ```addData()``` function call. 64 65The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to 66an archive.