{"id":13462112,"url":"https://github.com/Chumper/Zipper","last_synced_at":"2025-03-25T01:31:45.439Z","repository":{"id":10246315,"uuid":"12352238","full_name":"Chumper/Zipper","owner":"Chumper","description":"This is a simple Wrapper around the ZipArchive methods with some handy functions","archived":true,"fork":false,"pushed_at":"2020-02-25T12:04:51.000Z","size":147,"stargazers_count":847,"open_issues_count":65,"forks_count":269,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-07-31T12:07:35.681Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chumper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-25T01:05:33.000Z","updated_at":"2024-07-21T18:12:49.000Z","dependencies_parsed_at":"2022-08-07T05:15:37.014Z","dependency_job_id":null,"html_url":"https://github.com/Chumper/Zipper","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chumper%2FZipper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chumper%2FZipper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chumper%2FZipper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chumper%2FZipper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chumper","download_url":"https://codeload.github.com/Chumper/Zipper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222031154,"owners_count":16919368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T12:00:38.949Z","updated_at":"2024-10-29T10:30:47.173Z","avatar_url":"https://github.com/Chumper.png","language":"PHP","funding_links":[],"categories":["Uncategorized","PHP","资源管理( Asset Management )"],"sub_categories":["Uncategorized"],"readme":"# Note\n\nI haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5.\nI archived the repository for the reason that I am no longer working with PHP (we all have to move on sometimes) and have no time to take proper care of it anymore.\n\nFeel free to read the code, to fork it or to use it in whatever way you want.\n\n## Update 25th February 2020\n\nI have merged a PR that includes a security fixe to mitigate zip directory traversal attacks. \\\n**This package is still archived and should be swapped out with another package.** \\\nHowever, as long as security fixes will come in I see it as my basic obligation to update this package on demand.\n\n# Zipper\n\n[![Build Status](https://travis-ci.org/Chumper/Zipper.png)](https://travis-ci.org/Chumper/Zipper)\n\nThis is a simple Wrapper around the ZipArchive methods with some handy functions.\n\n## Installation\n\n1. Add this package to the list of required packages, inside `composer.json`\n  * for Laravel 5: `\"chumper/zipper\": \"1.0.x\"`\n  * ~~for Laravel 4: `\"chumper/zipper\": \"0.5.x\"`~~\n2. Run `composer update`\n\n3. Go to `app/config/app.php`\n\n  * add to providers `Chumper\\Zipper\\ZipperServiceProvider::class`\n  * add to aliases `'Zipper' =\u003e Chumper\\Zipper\\Zipper::class`\n\nYou can now access Zipper with the `Zipper` alias.\n\n## Simple example\n```php\n$files = glob('public/files/*');\nZipper::make('public/test.zip')-\u003eadd($files)-\u003eclose();\n```\n- 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/`.\n\n## Another example\n```php\n$zipper = new \\Chumper\\Zipper\\Zipper;\n\n$zipper-\u003emake('test.zip')-\u003efolder('test')-\u003eadd('composer.json');\n$zipper-\u003ezip('test.zip')-\u003efolder('test')-\u003eadd('composer.json','test');\n\n$zipper-\u003eremove('composer.lock');\n\n$zipper-\u003efolder('mySuperPackage')-\u003eadd(\n    array(\n        'vendor',\n        'composer.json'\n    ),\n);\n\n$zipper-\u003egetFileContent('mySuperPackage/composer.json');\n\n$zipper-\u003emake('test.zip')-\u003eextractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);\n\n$zipper-\u003eclose();\n```\n\nNote: Please be aware that you need to call `-\u003eclose()` at the end to write the zip file to disk.\n\nYou can easily chain most functions, except `getFileContent`, `getStatus`, `close` and `extractTo` which must come at the end of the chain.\n\nThe 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.\n\n\n# Functions\n\n## make($pathToFile)\n\n`Create` or `Open` a zip archive; if the file does not exists it will create a new one.\nIt will return the Zipper instance so you can chain easily.\n\n\n## add($files/folder)\n\nYou can add an array of Files, or a Folder and all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.\n\n\n## addString($filename, $content)\n\nadd a single file to the zip by specifying a name and the content as strings.\n\n\n## remove($file/s)\n\nremoves a single file or an array of files from the zip.\n\n\n## folder($folder)\n\nSpecify a folder to 'add files to' or 'remove files from' from the zip, example\n\n```php\nZipper::make('test.zip')-\u003efolder('test')-\u003eadd('composer.json');\nZipper::make('test.zip')-\u003efolder('test')-\u003eremove('composer.json');\n```\n\n## listFiles($regexFilter = null)\n\nLists all files within archive (if no filter pattern is provided). Use `$regexFilter` parameter to filter files. See [Pattern Syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php) for regular expression syntax \n\n\u003e NB: `listFiles` ignores folder set with `folder` function\n\n\nExample: Return all files/folders ending/not ending with '.log' pattern (case insensitive). This will return matches in sub folders and their sub folders also\n\n```php\n$logFiles = Zipper::make('test.zip')-\u003elistFiles('/\\.log$/i'); \n$notLogFiles = Zipper::make('test.zip')-\u003elistFiles('/^(?!.*\\.log).*$/i'); \n```\n\n\n## home()\n\nResets the folder pointer.\n\n## zip($fileName)\n\nUses the ZipRepository for file handling.\n\n\n## getFileContent($filePath)\n\nget the content of a file in the zip. This will return the content or false.\n\n\n## getStatus()\n\nget the opening status of the zip as integer.\n\n\n## close()\n\ncloses the zip and writes all changes.\n\n\n## extractTo($path)\n\nExtracts the content of the zip archive to the specified location, for example\n\n```php\nZipper::make('test.zip')-\u003efolder('test')-\u003eextractTo('foo');\n```\n\nThis 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`.\n\nThis command is really nice to get just a part of the zip file, you can also pass a 2nd \u0026 3rd param to specify a single or an array of files that will be\n\n\u003e NB: Php ZipArchive uses internally '/' as directory separator for files/folders in zip. So Windows users should not set \n\u003e whitelist/blacklist patterns with '\\' as it will not match anything\n\nwhite listed\n\n\u003e**Zipper::WHITELIST**\n\n```php\nZipper::make('test.zip')-\u003eextractTo('public', array('vendor'), Zipper::WHITELIST);\n```\n\nWhich will extract the `test.zip` into the `public` folder but **only** files/folders starting with `vendor` prefix inside the zip will be extracted.\n\nor black listed\n\n\u003e**Zipper::BLACKLIST**\nWhich will extract the `test.zip` into the `public` folder except files/folders starting with `vendor` prefix inside the zip will not be extracted.\n\n\n```php\nZipper::make('test.zip')-\u003eextractTo('public', array('vendor'), Zipper::BLACKLIST);\n```\n\n\u003e**Zipper::EXACT_MATCH**\n\n```php\nZipper::make('test.zip')\n    -\u003efolder('vendor')\n    -\u003eextractTo('public', array('composer', 'bin/phpunit'), Zipper::WHITELIST | Zipper::EXACT_MATCH);\n```\n\nWhich will extract the `test.zip` into the `public` folder but **only** files/folders **exact matching names**. So this will:\n * extract file or folder named `composer` in folder named `vendor` inside zip to `public` resulting `public/composer`\n * extract file or folder named `bin/phpunit` in `vendor/bin/phpunit` folder inside zip to `public` resulting `public/bin/phpunit`\n\n\u003e **NB:** extracting files/folder from zip without setting Zipper::EXACT_MATCH \n\u003e When zip has similar structure as below and only `test.bat` is given as whitelist/blacklist argument then `extractTo` would extract all those files and folders as they all start with given string\n\n```\ntest.zip\n |- test.bat\n |- test.bat.~\n |- test.bat.dir/\n    |- fileInSubFolder.log\n```\n\n## extractMatchingRegex($path, $regex)\n\nExtracts the content of the zip archive matching regular expression to the specified location. See [Pattern Syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php) for regular expression syntax.\n\nExample: extract all files ending with `.php` from `src` folder and its sub folders.\n```php\nZipper::make('test.zip')-\u003efolder('src')-\u003eextractMatchingRegex($path, '/\\.php$/i'); \n```\n\nExample: extract all files **except** those ending with `test.php` from `src` folder and its sub folders.\n```php\nZipper::make('test.zip')-\u003efolder('src')-\u003eextractMatchingRegex($path, '/^(?!.*test\\.php).*$/i'); \n```\n\n# Development\n\nMaybe it is a good idea to add other compression functions like rar, phar or bzip2 etc...\nEverything is setup for that, if you want just fork and develop further.\n\nIf you need other functions or got errors, please leave an issue on github.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChumper%2FZipper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChumper%2FZipper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChumper%2FZipper/lists"}