• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..Today-

src/HToday-2,1271,181

LICENSEH A D16-Sep-20211 KiB1916

README.mdH A D16-Sep-20212 KiB6952

phpunit.xmlH A D16-Sep-2021696 2221

README.md

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