Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from ctf0/master
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
Nils Plaschke committed Jan 8, 2015
2 parents e758ab9 + 15eb20c commit d1ab536
Showing 1 changed file with 84 additions and 57 deletions.
141 changes: 84 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,110 +6,137 @@ This is a simple Wrapper around the ZipArchive methods with some handy functions

##Installation

To install this package just require it in your `composer.json` with
1- To install this package just require it in your

"Chumper/Zipper": "0.5.0"
`composer.json` with `"Chumper/Zipper": "0.5.0"`

This package also includes Laravel 4 support, to activate it add
2- goto `app/config/app.php`

'Chumper\Zipper\ZipperServiceProvider'
.add to providers

to the service providers in the `app.php`
'Chumper\Zipper\ZipperServiceProvider'

You can then access Zipper with the `Zipper` alias.
.add to aliases

'Zipper' => 'Chumper\Zipper\Zipper'

You can now access Zipper with the `Zipper` alias.

##Simple example
```php
$files = glob('public/files/*');
Zipper::make('public/test.zip')->add($files);
```
- by default the package will create the `test.zip` in the project route folder but in the example above we changed it to `project_route/public/`.

$zipper = new \Chumper\Zipper\Zipper;
####Another example
```php
$zipper = new \Chumper\Zipper\Zipper;

$zipper->make('test.zip')->folder('test')->add('composer.json');
$zipper->zip('test.zip')->folder('test')->add('composer.json','test');

$zipper->remove('composer.lock');
$zipper->make('test.zip')->folder('test')->add('composer.json');
$zipper->zip('test.zip')->folder('test')->add('composer.json','test');

$zipper->folder('mySuperPackage')->add(
array(
'vendor',
'composer.json'
),
);
$zipper->remove('composer.lock');

$zipper->getFileContent('mySuperPackage/composer.json');

$zipper->make('test.zip')->extractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);

You can easily chain most functions, functions that are not chainable are `getFileContent`, `close`, `extractTo` and `getStatus`
$zipper->folder('mySuperPackage')->add(
array(
'vendor',
'composer.json'
),
);

The main reason i wrote this little package is the `extractTo` method since it allows you to be very flexible when extracting zips.
So you can for example implement an update method which will just override the changed files.
$zipper->getFileContent('mySuperPackage/composer.json');

$zipper->make('test.zip')->extractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);
```

$zipper->make('test.zip')->extractTo('public', array('vendor'), Zipper::BLACKLIST);

This will extract the `test.zip` into the `public` folder except the folder `vendor` inside the zip will not be extracted.
- You can easily chain most functions, except `getFileContent`, `getStatus`, `close` and `extractTo` which must come at the end of the chaine.

$zipper->make('test.zip')->extractTo('public', array('vendor'), Zipper::WHITELIST);

This will extract the `test.zip` into the `public` folder but **only** the folder `vendor` inside the zip will be extracted.
The main reason i wrote this little package is the `extractTo` method since it allows you to be very flexible when extracting zips.
So you can for example implement an update method which will just override the changed files.

$zipper->make('test.zip')->folder('test')->extractTo('foo');

This will go into the folder `test` in the zip file and extract the content of the folder to the folder `foo`.
This command is really nice to get just a part of the zip file.

##Functions

**make($pathToFile)**

create or open a zip archive; if the file does not exists it will create a new one.
It will return the Zipper instance so you can chain easily
`Create` or `Open` a zip archive; if the file does not exists it will create a new one.
It will return the Zipper instance so you can chain easily.


**extractTo($path, array $files = array(), $method = Zipper::BLACKLIST)**
**add($files/folder)**

Extracts the content of the zip archive to the specified location.
You can specify an array or string of files that will be white listed or black listed based on the third parameter
You can add and array of Files, or a Folder which all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.


**getFileContent($filePath)**
**addString($filename, $content)**

get the content of a file in the zip. This will return the content or false.
add a single file to the zip by specifying a name and content as strings.


**add($pathToAdd)**
**remove($file/s)**

add a string or an array of files to the zip
You can name files or folder, all files in the folder then will be added.
removes a single file or an array of files from the zip.

**addString($filename, $content)**

add a file to the zip by specifying a name and content as strings
**folder($folder)**

Specify a folder to 'add files to' or 'remove files from' from the zip, example

**getStatus()**
Zipper::make('test.zip')->folder('test')->add('composer.json');
Zipper::make('test.zip')->folder('test')->remove('composer.json');

get the opening status of the zip as integer

**home()**

**remove($fileToRemove)**
Resets the folder pointer.

removes a single file or an array of files from the zip.

**zip($fileName)**

Uses the ZipRepository for file handling.


**getFileContent($filePath)**

get the content of a file in the zip. This will return the content or false.


**getStatus()**

get the opening status of the zip as integer.


**close()**

closes the zip and writes all changes
closes the zip and writes all changes.

**folder($folder)**

Sets the internal pointer to this folder
**extractTo($path)**

**home()**
Extracts the content of the zip archive to the specified location, for example

Resets the folder pointer
Zipper::make('test.zip')->folder('test')->extractTo('foo');

This will go into the folder `test` in the zip file and extract the content of that folder only to the folder `foo`, this is equal to using the `Zipper::WHITELIST`.

This command is really nice to get just a part of the zip file, you can also pass a 2nd & 3rd param to specify a single or an array of files that will be

white listed

>**Zipper::WHITELIST**
>
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::WHITELIST);
Which will extract the `test.zip` into the `public` folder but **only** the folder `vendor` inside the zip will be extracted.

or black listed

>**Zipper::BLACKLIST**
>
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::BLACKLIST);
Which will extract the `test.zip` into the `public` folder except the folder `vendor` inside the zip will not be extracted.

**zip($fileName)**

USes the ZipRepository for file handling

##Development

Expand Down

0 comments on commit d1ab536

Please sign in to comment.