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. 23 24Check the [API docs](https://splitbrain.github.io/php-archive/) for more 25info. 26 27 28```php 29require_once 'vendor/autoload.php'; 30use splitbrain\PHPArchive\Tar; 31 32// To list the contents of an existing TAR archive, open() it and use 33// contents() on it: 34$tar = new Tar(); 35$tar->open('myfile.tgz'); 36$toc = $tar->contents(); 37print_r($toc); // array of FileInfo objects 38 39// To extract the contents of an existing TAR archive, open() it and use 40// extract() on it: 41$tar = new Tar(); 42$tar->open('myfile.tgz'); 43$tar->extract('/tmp'); 44 45// To create a new TAR archive directly on the filesystem (low memory 46// requirements), create() it: 47$tar = new Tar(); 48$tar->create('myfile.tgz'); 49$tar->addFile(...); 50$tar->addData(...); 51... 52$tar->close(); 53 54// To create a TAR archive directly in memory, create() it, add*() 55// files and then either save() or getArchive() it: 56$tar = new Tar(); 57$tar->setCompression(9, Archive::COMPRESS_BZIP); 58$tar->create(); 59$tar->addFile(...); 60$tar->addData(...); 61... 62$tar->save('myfile.tbz'); // compresses and saves it 63echo $tar->getArchive(); // compresses and returns it 64``` 65 66Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore 67you can call ```setCompression``` before each ```addFile()``` and ```addData()``` function call. 68 69The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to 70an archive. 71