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