2017 © Pedro Peláez
 

library zipper

This is a little neat helper for the ZipArchive methods with handy functions

image

zorx/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  • Saturday, June 4, 2016
  • by zorx
  • Repository
  • 1 Watchers
  • 1 Stars
  • 430 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 96 Forks
  • 0 Open issues
  • 8 Versions
  • 13 % Grown

The README.md

Zipper

Build Status, (*1)

This is a simple Wrapper around the ZipArchive methods with some handy functions., (*2)

Installation

  1. Add this package to the list of required packages, inside composer.json
    • for Laravel 5: "chumper/zipper": "0.6.x"
    • for Laravel 4: "chumper/zipper": "0.5.x"
  2. Run composer update, (*3)

  3. Go to app/config/app.php, (*4)

  • add to providers 'Chumper\Zipper\ZipperServiceProvider'
  • add to aliases 'Zipper' => 'Chumper\Zipper\Zipper'

You can now access Zipper with the Zipper alias., (*5)

Simple example

$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/.

Another example

$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->folder('mySuperPackage')->add(
    array(
        'vendor',
        'composer.json'
    ),
);

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

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

You can easily chain most functions, except getFileContent, getStatus, close and extractTo which must come at the end of the chain., (*6)

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., (*7)

Functions

make($pathToFile), (*8)

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., (*9)

add($files/folder), (*10)

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/';., (*11)

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

add a single file to the zip by specifying a name and content as strings., (*13)

remove($file/s), (*14)

removes a single file or an array of files from the zip., (*15)

folder($folder), (*16)

Specify a folder to 'add files to' or 'remove files from' from the zip, example, (*17)

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

home(), (*18)

Resets the folder pointer., (*19)

zip($fileName), (*20)

Uses the ZipRepository for file handling., (*21)

getFileContent($filePath), (*22)

get the content of a file in the zip. This will return the content or false., (*23)

getStatus(), (*24)

get the opening status of the zip as integer., (*25)

close(), (*26)

closes the zip and writes all changes., (*27)

extractTo($path), (*28)

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

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., (*30)

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, (*31)

white listed, (*32)

Zipper::WHITELIST, (*33)

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., (*34)

or black listed, (*35)

Zipper::BLACKLIST, (*36)

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., (*37)

Development

Maybe it is a good idea to add other compression functions like rar, phar or bzip2 etc... Everything is setup for that, if you want just fork and develop further., (*38)

If you need other functions or got errors, please leave an issue on github., (*39)

The Versions

04/06 2016

dev-master

9999999-dev http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

04/06 2016

0.6.3

0.6.3.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

18/04 2016

0.6.2

0.6.2.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

16/02 2015

0.6.1

0.6.1.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

13/02 2015

dev-l4

dev-l4 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

13/02 2015

0.6.0

0.6.0.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

08/01 2015

0.5.1

0.5.1.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive

25/11 2014

0.5.0

0.5.0.0 http://github.com/Chumper/zipper

This is a little neat helper for the ZipArchive methods with handy functions

  Sources   Download

Apache2

The Requires

 

The Development Requires

laravel zip archive