1
0
mirror of https://github.com/splitbrain/php-archive.git synced 2025-01-17 13:38:26 +01:00
php-archive/README.md

71 lines
2.1 KiB
Markdown
Raw Normal View History

2015-02-20 15:38:09 +01:00
PHPArchive - Pure PHP ZIP and TAR handling
==========================================
This library allows to handle new ZIP and TAR archives without the need for any special PHP extensions (gz and bzip are
needed for compression). It can create new files or extract existing ones.
To keep things simple, the modification (adding or removing files) of existing archives is not supported.
[![Build Status](https://travis-ci.org/splitbrain/php-archive.svg)](https://travis-ci.org/splitbrain/php-archive)
2015-02-20 15:38:09 +01:00
Install
-------
Use composer:
2015-02-20 15:43:24 +01:00
```php composer.phar require splitbrain/php-archive```
2015-02-20 15:38:09 +01:00
Usage
-----
2015-06-29 21:45:00 +02:00
The usage for the Zip and Tar classes are basically the same. Here are some
Add script and travis setup to automatically create docs Squashed commit of the following: commit aa7366d65b8b24542c08651d1f8b8bb3ce6f5001 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 21:06:13 2015 +0200 removed apigen.phar, setup .gitignore commit 12a3da7477614ecc1d55318fe4551fbe1b92a0bc Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 21:03:45 2015 +0200 added some info within the generate-api script commit 47215ea47472db6e15a07795861c83962339cf77 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:56:11 2015 +0200 added API docs to readme commit d67bda30107c0280c9f562e5e2156a0b0b6c2b6b Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:53:19 2015 +0200 abort when DST does not exist commit 2e769082a64040b1dc3583218ca96be6e8c481de Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:52:25 2015 +0200 Revert "try to set autocomplete values" This reverts commit 914d42546a1390250f858b08c172df4cc0d783df. commit 914d42546a1390250f858b08c172df4cc0d783df Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:50:21 2015 +0200 try to set autocomplete values commit e53cd155119ffb6be273f31233bd7ff3ad9f67cc Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:44:32 2015 +0200 added apigen config commit c32fa34db6cc67eeff4f6f0504759214876dfbdf Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:34:47 2015 +0200 fixed trigger branch commit 5bb8f757197cca9169a0264ce1e8f85aa4f6a74a Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:31:04 2015 +0200 another go commit 9e806b62360f315e24ae5586c1a9cbd94644acfa Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:26:53 2015 +0200 adjusted logic for travis compile commit 1b4e03ebd792d10ba67914404f357c1678d5a950 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:22:45 2015 +0200 first go at automatic apidoc building
2015-08-05 21:07:59 +02:00
examples for working with TARs to get you started.
Check the [API docs](https://splitbrain.github.io/php-archive/) for more
info.
2015-02-20 15:38:09 +01:00
```php
2015-06-29 21:45:00 +02:00
require_once 'vendor/autoload.php';
2015-02-20 15:38:09 +01:00
use splitbrain\PHPArchive\Tar;
2015-06-29 21:45:00 +02:00
// To list the contents of an existing TAR archive, open() it and use
// contents() on it:
2015-02-20 15:38:09 +01:00
$tar = new Tar();
$tar->open('myfile.tgz');
$toc = $tar->contents();
print_r($toc); // array of FileInfo objects
2015-06-29 21:45:00 +02:00
// To extract the contents of an existing TAR archive, open() it and use
// extract() on it:
2015-02-20 15:38:09 +01:00
$tar = new Tar();
$tar->open('myfile.tgz');
$tar->extract('/tmp');
2015-06-29 21:45:00 +02:00
// To create a new TAR archive directly on the filesystem (low memory
// requirements), create() it:
2015-02-20 15:38:09 +01:00
$tar = new Tar();
$tar->create('myfile.tgz');
$tar->addFile(...);
$tar->addData(...);
...
$tar->close();
2015-06-29 21:45:00 +02:00
// To create a TAR archive directly in memory, create() it, add*()
// files and then either save() or getArchive() it:
2015-02-20 15:38:09 +01:00
$tar = new Tar();
2015-08-12 11:46:20 +02:00
$tar->setCompression(9, Archive::COMPRESS_BZIP);
2015-02-20 15:38:09 +01:00
$tar->create();
$tar->addFile(...);
$tar->addData(...);
...
2015-08-12 11:46:20 +02:00
$tar->save('myfile.tbz'); // compresses and saves it
echo $tar->getArchive(); // compresses and returns it
2015-02-20 15:38:09 +01:00
```
2015-06-29 21:45:00 +02:00
Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore
you can call ```setCompression``` before each ```addFile()``` and ```addData()``` function call.
2015-02-20 15:38:09 +01:00
The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to
Add script and travis setup to automatically create docs Squashed commit of the following: commit aa7366d65b8b24542c08651d1f8b8bb3ce6f5001 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 21:06:13 2015 +0200 removed apigen.phar, setup .gitignore commit 12a3da7477614ecc1d55318fe4551fbe1b92a0bc Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 21:03:45 2015 +0200 added some info within the generate-api script commit 47215ea47472db6e15a07795861c83962339cf77 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:56:11 2015 +0200 added API docs to readme commit d67bda30107c0280c9f562e5e2156a0b0b6c2b6b Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:53:19 2015 +0200 abort when DST does not exist commit 2e769082a64040b1dc3583218ca96be6e8c481de Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:52:25 2015 +0200 Revert "try to set autocomplete values" This reverts commit 914d42546a1390250f858b08c172df4cc0d783df. commit 914d42546a1390250f858b08c172df4cc0d783df Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:50:21 2015 +0200 try to set autocomplete values commit e53cd155119ffb6be273f31233bd7ff3ad9f67cc Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:44:32 2015 +0200 added apigen config commit c32fa34db6cc67eeff4f6f0504759214876dfbdf Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:34:47 2015 +0200 fixed trigger branch commit 5bb8f757197cca9169a0264ce1e8f85aa4f6a74a Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:31:04 2015 +0200 another go commit 9e806b62360f315e24ae5586c1a9cbd94644acfa Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:26:53 2015 +0200 adjusted logic for travis compile commit 1b4e03ebd792d10ba67914404f357c1678d5a950 Author: Andreas Gohr <andi@splitbrain.org> Date: Wed Aug 5 20:22:45 2015 +0200 first go at automatic apidoc building
2015-08-05 21:07:59 +02:00
an archive.