1
0
mirror of https://github.com/splitbrain/php-archive.git synced 2025-01-16 13:09:12 +01:00

added license and readme

This commit is contained in:
Andreas Gohr 2015-02-20 15:38:09 +01:00
parent c948130add
commit 0bb99824e2
5 changed files with 96 additions and 39 deletions

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2015 Andreas Gohr <gohr@cosmocode.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

59
README.md Normal file
View File

@ -0,0 +1,59 @@
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.
Install
-------
Use composer:
```php composer.phar require splitbrain/PHPArchive```
Usage
-----
The usage for the Zip and Tar classes are basically the same. Here are some examples for working with TARs to get
you started. Check the source code comments for more info
```php
use splitbrain\PHPArchive\Tar;
// To list the contents of an existing TAR archive, open() it and use contents() on it:
$tar = new Tar();
$tar->open('myfile.tgz');
$toc = $tar->contents();
print_r($toc); // array of FileInfo objects
// To extract the contents of an existing TAR archive, open() it and use extract() on it:
$tar = new Tar();
$tar->open('myfile.tgz');
$tar->extract('/tmp');
// To create a new TAR archive directly on the filesystem (low memory requirements), create() it,
$tar = new Tar();
$tar->create('myfile.tgz');
$tar->addFile(...);
$tar->addData(...);
...
$tar->close();
// To create a TAR archive directly in memory, create() it, add*() files and then either save()
// or getData() it:
$tar = new Tar();
$tar->create();
$tar->addFile(...);
$tar->addData(...);
...
$tar->save('myfile.tgz'); // compresses and saves it
echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it
```
Differences between Tar and Zip: Tars are compressed as a whole while Zips compress each file individually. Therefore
```Zip``` accepts an additional compression level parameter in the ```addFile()``` and ```addData()``` functions.
The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to
an archive.

View File

@ -6,6 +6,10 @@ namespace splitbrain\PHPArchive;
* Class FileInfo
*
* stores meta data about a file in an Archive
*
* @author Andreas Gohr <andi@splitbrain.org>
* @package splitbrain\PHPArchive
* @license MIT
*/
class FileInfo
{

View File

@ -3,49 +3,15 @@
namespace splitbrain\PHPArchive;
/**
* This class allows the extraction of existing and the creation of new Unix TAR archives.
* To keep things simple, the modification of existing archives is not supported. It handles
* uncompressed, gzip and bzip2 compressed tar files.
* Class Tar
*
* Creates or extracts Tar archives. Supports gz and bzip compression
*
* Long pathnames (>100 chars) are supported in POSIX ustar and GNU longlink formats.
*
* To list the contents of an existing TAR archive, open() it and use contents() on it:
*
* $tar = new Tar();
* $tar->open('myfile.tgz');
* $toc = $tar->contents();
* print_r($toc);
*
* To extract the contents of an existing TAR archive, open() it and use extract() on it:
*
* $tar = new Tar();
* $tar->open('myfile.tgz');
* $tar->extract('/tmp');
*
* To create a new TAR archive directly on the filesystem (low memory requirements), create() it,
* add*() files and close() it:
*
* $tar = new Tar();
* $tar->create('myfile.tgz');
* $tar->addFile(...);
* $tar->addData(...);
* ...
* $tar->close();
*
* To create a TAR archive directly in memory, create() it, add*() files and then either save()
* or getData() it:
*
* $tar = new Tar();
* $tar->create();
* $tar->addFile(...);
* $tar->addData(...);
* ...
* $tar->save('myfile.tgz'); // compresses and saves it
* echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Bouchon <tarlib@bouchon.org> (Maxg)
* @license GPL 2
* @package splitbrain\PHPArchive
* @license MIT
*/
class Tar extends Archive
{

View File

@ -2,6 +2,15 @@
namespace splitbrain\PHPArchive;
/**
* Class Zip
*
* Creates or extracts Zip archives
*
* @author Andreas Gohr <andi@splitbrain.org>
* @package splitbrain\PHPArchive
* @license MIT
*/
class Zip
{