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