All Projects → madnest → madzipper

madnest / madzipper

Licence: MIT license
Wannabe successor of Chumper/Zipper package for Laravel

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to madzipper

Miscellaneous R Code
Code that might be useful to others for learning/demonstration purposes, specifically along the lines of modeling and various algorithms. Now almost entirely superseded by the models-by-example repo.
Stars: ✭ 146 (+28.07%)
Mutual labels:  zip
Zydra
Stars: ✭ 178 (+56.14%)
Mutual labels:  zip
Vue Blog
🎉 基于vue全家桶 + element-ui 构建的一个后台管理集成解决方案
Stars: ✭ 208 (+82.46%)
Mutual labels:  zip
Libarchivejs
Archive library for browsers
Stars: ✭ 145 (+27.19%)
Mutual labels:  zip
Zip
Swift framework for zipping and unzipping files.
Stars: ✭ 2,120 (+1759.65%)
Mutual labels:  zip
Bkcrack
Crack legacy zip encryption with Biham and Kocher's known plaintext attack.
Stars: ✭ 178 (+56.14%)
Mutual labels:  zip
Quickpkg
wrapper for pkgbuild to quickly build simple packages from an installed app, a dmg or zip archive.
Stars: ✭ 137 (+20.18%)
Mutual labels:  zip
Zip
Robust ZIP decoder with defenses against dangerous compression ratios, spec deviations, malicious archive signatures, mismatching local and central directory headers, ambiguous UTF-8 filenames, directory and symlink traversals, invalid MS-DOS dates, overlapping headers, overflow, underflow, sparseness, accidental buffer bleeds etc.
Stars: ✭ 254 (+122.81%)
Mutual labels:  zip
Libzippp
C++ wrapper for libzip
Stars: ✭ 169 (+48.25%)
Mutual labels:  zip
Zip.js
JavaScript library to zip and unzip files in the browser and Deno
Stars: ✭ 2,444 (+2043.86%)
Mutual labels:  zip
Flametree
🔥 Python file and zip operations made easy
Stars: ✭ 148 (+29.82%)
Mutual labels:  zip
Expresscart
A fully functioning Node.js shopping cart with Stripe, PayPal, Authorize.net, PayWay, Blockonomics, Adyen, Zip and Instore payments.
Stars: ✭ 2,069 (+1714.91%)
Mutual labels:  zip
Node Archiver
a streaming interface for archive generation
Stars: ✭ 2,300 (+1917.54%)
Mutual labels:  zip
Uvtools
MSLA/DLP, file analysis, calibration, repair, conversion and manipulation
Stars: ✭ 148 (+29.82%)
Mutual labels:  zip
Turbobench
Compression Benchmark
Stars: ✭ 211 (+85.09%)
Mutual labels:  zip
Zipstorer
A Pure C# Class to Store Files in Zip
Stars: ✭ 139 (+21.93%)
Mutual labels:  zip
Mod zip
Streaming ZIP archiver for nginx 📦
Stars: ✭ 178 (+56.14%)
Mutual labels:  zip
Shigureader
用Chrome或者iPad轻松阅读整理漫画,播放音乐,以及观看视频. All-in-one solution for local doujin/anime/music file.
Stars: ✭ 254 (+122.81%)
Mutual labels:  zip
Unifiedarchive
UnifiedArchive - an archive manager with a unified way for different formats. Supports all basic (listing, reading, extracting and creation) and specific features (compression level, password-protection). Bundled with console program for working with archives.
Stars: ✭ 246 (+115.79%)
Mutual labels:  zip
Datacompression
Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)
Stars: ✭ 191 (+67.54%)
Mutual labels:  zip

Madzipper

This is a simple Wrapper around the ZipArchive methods with some handy functions.

Build Status

Installation

  1. madnest/madzipper can be installed by running:
composer require madnest/madzipper
  1. Optionally when using with Laravel, go to app/config/app.php
  • add to providers Madnest\Madzipper\MadzipperServiceProvider::class

You can now access Madzipper with the Madzipper alias.

Versions

Package Laravel PHP
v1.4 10.* ^8.1
v1.3 9.* ^8.0
v1.2 7.* / 8.* ^8.0

Simple Laravel example by using Madzipper facade

$files = glob('public/files/*');
Madzipper::make('public/test.zip')->add($files)->close();
  • 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 \Madnest\Madzipper\Madzipper;

$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('', ['mySuperPackage/composer.json'], Madzipper::WHITELIST);

$zipper->close();

Note: Please be aware that you need to call ->close() at the end to write the zip file to disk.

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

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.

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.

add($files/folder)

You 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/';.

addString($filename, $content)

add a single file to the zip by specifying a name and the content as strings.

remove($file/s)

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

folder($folder)

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

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

listFiles($regexFilter = null)

Lists all files within archive (if no filter pattern is provided). Use $regexFilter parameter to filter files. See Pattern Syntax for regular expression syntax

NB: listFiles ignores folder set with folder function

Example: Return all files/folders ending/not ending with '.log' pattern (case insensitive). This will return matches in sub folders and their sub folders also

$logFiles = Madzipper::make('test.zip')->listFiles('/\.log$/i');
$notLogFiles = Madzipper::make('test.zip')->listFiles('/^(?!.*\.log).*$/i');

home()

Resets the folder pointer.

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.

extractTo($path)

Extracts the content of the zip archive to the specified location, for example

Madzipper::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 Madzipper::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

NB: Php ZipArchive uses internally '/' as directory separator for files/folders in zip. So Windows users should not set whitelist/blacklist patterns with '' as it will not match anything

white listed

Madzipper::WHITELIST

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

Which will extract the test.zip into the public folder but only files/folders starting with vendor prefix inside the zip will be extracted.

or black listed

Madzipper::BLACKLIST Which will extract the test.zip into the public folder except files/folders starting with vendor prefix inside the zip will not be extracted.

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

Madzipper::EXACT_MATCH

Madzipper::make('test.zip')
    ->folder('vendor')
    ->extractTo('public', array('composer', 'bin/phpunit'), Madzipper::WHITELIST | Madzipper::EXACT_MATCH);

Which will extract the test.zip into the public folder but only files/folders exact matching names. So this will:

  • extract file or folder named composer in folder named vendor inside zip to public resulting public/composer
  • extract file or folder named bin/phpunit in vendor/bin/phpunit folder inside zip to public resulting public/bin/phpunit

NB: extracting files/folder from zip without setting Madzipper::EXACT_MATCH 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

test.zip
 |- test.bat
 |- test.bat.~
 |- test.bat.dir/
    |- fileInSubFolder.log

extractMatchingRegex($path, $regex)

Extracts the content of the zip archive matching regular expression to the specified location. See Pattern Syntax for regular expression syntax.

Example: extract all files ending with .php from src folder and its sub folders.

Madzipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/\.php$/i');

Example: extract all files except those ending with test.php from src folder and its sub folders.

Madzipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/^(?!.*test\.php).*$/i');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

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.

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

Credits

@Chumper

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].