Giter Site home page Giter Site logo

zippy's Introduction

Zippy

License Packagist Travis Scrutinizer Packagist

A PHP library to read, create, and extract archives in various formats via command line utilities or PHP extensions

Installation

The only supported installation method is via Composer. Run the following command to require Zippy in your project:

composer require alchemy/zippy

Adapters

Zippy currently supports the following drivers and file formats:

  • zip
    • .zip
  • PHP zip extension
    • .zip
  • GNU tar
    • .tar
    • .tar.gz
    • .tar.bz2
  • BSD tar
    • .tar
    • .tar.gz
    • .tar.bz2

Getting started

All the following code samples assume that Zippy is loaded and available as $zippy. You need the following code (or variation of) to load Zippy:

<?php

use Alchemy\Zippy\Zippy;

// Require Composer's autoloader
require __DIR__ . '/vendor/autoload.php';

// Load Zippy
$zippy = Zippy::load();

List an archive's contents:

// Open an archive
$archive = $zippy->open('build.tar');

// Iterate through members
foreach ($archive as $member) {
    echo "Archive contains $member" . PHP_EOL;
}

Extract an archive to a specific directory:

// Open an archive
$archive = $zippy->open('build.tar');

// Extract archive contents to `/tmp`
$archive->extract('/tmp');

Create a new archive

// Creates an archive.zip that contains a directory "folder" that contains
// files contained in "/path/to/directory" recursively
$archive = $zippy->create('archive.zip', array(
    'folder' => '/path/to/directory'
), true);

Customize file and directory names inside archive

$archive = $zippy->create('archive.zip', array(
    'folder' => '/path/to/directory',            // will create a folder at root
    'http://www.google.com/logo.jpg',            // will create a logo.jpg file at root
    fopen('https://www.facebook.com/index.php'), // will create an index.php at root
    'directory/image.jpg' => 'image.jpg',        // will create a image.jpg in 'directory' folder
));

Documentation

Documentation hosted at read the docs !

License

This project is licensed under the MIT license.

zippy's People

Contributors

aynsix avatar aztech-dev avatar bburnichon avatar bitdeli-chef avatar fabre-thibaud avatar fanno avatar func0der avatar giantcowfilms avatar jducro avatar joachimdoerr avatar jygaulier avatar koc avatar max-kovpak avatar mykiwi avatar nlegoff avatar nmaillat avatar paulredmond avatar pborreli avatar pgodel avatar romainneutron avatar scrutinizer-auto-fixer avatar yosmanyga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zippy's Issues

Function basename is not safe in UTF-8

PHP basename function is not safe in UTF-8 system, If the filename starts with an utf8 character, this character will be cut off. Example:

 echo basename('Ängelholm');
// print  'ngelholm'

Might be worth define a _basename function and all basename function change to _basename.

Unable to create archive

try use this code ,but its show Unable to create archive
directory has 777 promission

use Alchemy\Zippy\Zippy;

$zippy = Zippy::load();
// creates an archive.zip that contains a directory "folder" that contains
// files contained in "/path/to/directory" recursively
$archive = $zippy->create('archive.zip', array(
    'folder' => '/path/to/directory'
), recursive = true);

Adapter Factory & Strategy

Implements factory & strategy to get the best zip adapter according to the current platform and available adapter

$adapter = Zippy\Adapter\Factory::getAdapter('zip');
$adapter = Zippy\Adapter\Factory::getAdapter('tar');

Zip archive error

Trying to get iterator for zip archive and it fails at ZipAdapter:120 when creating new member because $member[mtime] is not \DateTime

member = Array
(
[location] => Invoice INVD063737 DD 19AUG16 RM10,567.82 - GO TRAVEL UN LIMITED.pdf
[size] => 53273
[mtime] => false
[is_dir] => false
)

Error:
Exception 'TypeError' with message 'Argument 5 passed to Alchemy\Zippy\Archive\Member::__construct() must be an instance of DateTime, boolean given, called in /private/var/www/jr_ota/vendor/alchemy/zippy/src/Adapter/ZipAdapter.php on line 126'

in /private/var/www/jr_ota/vendor/alchemy/zippy/src/Archive/Member.php:74

Stack trace:
#0 /private/var/www/jr_ota/vendor/alchemy/zippy/src/Adapter/ZipAdapter.php(126): Alchemy\Zippy\Archive\Member->__construct(Object(Alchemy\Zippy\Adapter\Resource\FileResource), Object(Alchemy\Zippy\Adapter\ZipAdapter), 'Invoice INVD063...', '53273', false, false)
#1 /private/var/www/jr_ota/vendor/alchemy/zippy/src/Adapter/AbstractAdapter.php(68): Alchemy\Zippy\Adapter\ZipAdapter->doListMembers(Object(Alchemy\Zippy\Adapter\Resource\FileResource))

Argument 5 passed to Alchemy\Zippy\Archive\Member::__construct() must be an instance of DateTime

Hi,

I'm trying to open this zip file;
https://github.com/GoktugOzturk/tet-boardsports/archive/master.zip
On my localhost (windows 10 & php 5.6 )
It works fine.
But on my staging server (Centos & PHP 7.0.6 )
Error occurs:
Argument 5 passed to Alchemy\Zippy\Archive\Member::__construct() must be an instance of DateTime, boolean given, called in /home/project/_shared/vendor/alchemy/zippy/src/Adapter/ZipAdapter.php on line 126

$zippy = \Alchemy\Zippy\Zippy::load();
$archive = $zippy->open($tmpFile);
$archive->extract($tmpThemeDir);
if (!file_exists($tmpThemeDir . "/theme/theme.json")) {
    /** @var \Alchemy\Zippy\Archive\MemberInterface[] $zipContents */
    $zipContents = $archive->getMembers();
    foreach ($zipContents as $zipContent) {
        if (substr($zipContent->getLocation(), -16) == "theme/theme.json") {
            $tmpThemeDir .= DIRECTORY_SEPARATOR . str_replace("/theme/theme.json", "", $zipContent->getLocation());
        }
    }
}

TarGNUTarAdapter.php broken

In recent versions of tar, the combo of "--overwrite" "--overwrite-dir" is now an error.

[ERROR] Unable to execute the following command '/bin/tar' '--extract' '--file=/tmp/payment.tar.gz' '--overwrite-dir'   '--overwrite' '--gzip' '--directory' '[OMITTED]' {output: /bin/tar:             
 '--overwrite' cannot be used with '--overwrite-dir'                                                                    
 Try '/bin/tar --help' or '/bin/tar --usage' for more information.                                                      
 }

Is output from drupal console, using the alchemy/zippy module inside its phar file.

UTF-8 Filename saving problem

All my files in the directory is utf8 encode, after zipped all filenames are converted to LATIN characters.

Greeting from Cambodia.

the size of this package makes it "unusable"

Could you please add: .gitattributes
eg:
docs/ export-ignore
tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
CHANGELOG.md export-ignore
README.md export-ignore
composer.lock export-ignore
phpunit-functional.xml.dist export-ignore
phpunit.xml.dist export-ignore

This means if "checking" out for production using composer the files listed here will be ignored and not included in the packages making the size ~130k instead of 17.2Mb

because including 17.2MB in our project is not an option.

-Thanks

can't create folder inside zip

When i try to add a file to the root of the archive it works. But when i try to add a file to a folder inside the archive it fails.

$filePathArray["filename.jpg"] = "/some/path/to/filename.jpg" OK
$filePathArray["folder/filename.jpg"] = "/some/path/to/filename.jpg" FAIL
$archive = $zippy->create($zipFilePath, $filePathArray);

Zipping without folder name

I can't make zippy use only the contents of a folder, it always requires at least one folder up.

For instance:

$source_dir = '/my/path/to/dir';
// Contains: file1, file2, dir1/

$zippy->create('myarchive.zip', $source_dir);
// will contain: 
// my/path/to/dir/file1
// my/path/to/dir/file2
// my/path/to/dir/dir1/....

How can I have only

file1
file2
dir1/....  ?

IOException on IIS 8 when calling ResourceManager->cleanup()

zip was successfully created,
but triggers error when unable to clean tmp files in IIS 8 Windows Server 2012 r2 (permission denied?)
should there be a fallback when the temp folder is undeleteable?
or, is it better to add an option whether to 'delete the temp on demand' or 'just leave OS do their stuff' ?

thank you

Stacktrace:

IOException in Filesystem.php line 169:
Fa
OException in Filesystem.php line 169:
Failed to remove directory "C:\Windows\TEMP/zippy_56d7a6f724d9f".
in Filesystem.php line 169
at Filesystem->remove('C:\Windows\TEMP/zippy_56d7a6f724d9f') in ResourceManager.php line 89
at ResourceManager->cleanup(object(ResourceCollection)) in ZipExtensionAdapter.php line 290
at ZipExtensionAdapter->addEntries(object(ZipArchiveResource), array('folder' => '../storage/app/cakil/report_delegasi_1456973558/'), true) in ZipExtensionAdapter.php line 207
at ZipExtensionAdapter->doCreate('C:\inetpub\wwwroot\portal-spd-ditpsmk\public\uploads\reports\forms\single/report_1_11.zip', array('folder' => '../storage/app/cakil/report_delegasi_1456973558/'), true) in AbstractAdapter.php line 58
at AbstractAdapter->create('uploads/reports/forms/single/report_1_11.zip', array('folder' => '../storage/app/cakil/report_delegasi_1456973558/'), true) in Zippy.php line 68
at Zippy->create('uploads/reports/forms/single/report_1_11.zip', array('folder' => '../storage/app/cakil/report_delegasi_1456973558/'), true) in FormsReportSingleController.php line 768
at FormsReportSingleController->_generateReportType1(object(CompetitionForms), object(CompetitionFormsResponses)) in FormsReportSingleController.php line 132
at FormsReportSingleController->getReportSingle(object(Request), '1', '11')
at call_user_func_array(array(object(FormsReportSingleController), 'getReportSingle'), array(object(Request), 'id' => '1', 'user_id' => '11')) in Controller.php line 78
at Controller->callAction('getReportSingle', array(object(Request), 'id' => '1', 'user_id' => '11')) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(FormsReportSingleController), object(Route), 'getReportSingle') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(FormsReportSingleController), object(Route), object(Request), 'getReportSingle') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Backend\FormsReportSingleController', 'getReportSingle') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 28
at Authenticate->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->hane(object(Request)) in index.php line 54

No adapter available for tar.gz on this platform

Hi,
I get an NoAdapterOnPlatformException when I attempt to create a tar.gz archive, not sure what I'm missing:

    $zippy = Zippy::load();
    $zippy->create('test.tar.gz', 'testfiles/');

tar also fails, No adapter available for tar on this platform

    $zippy = Zippy::load();
    $zippy->create('test.tar', 'testfiles/');

Creating a zip archive does succeed, however.

Zippy 0.3.2 on Ubuntu 14.04.3 LTS

Trace:


Fatal error:  Uncaught exception 'Alchemy\Zippy\Exception\NoAdapterOnPlatformException' with message 'No adapter available for tar.gz on this platform' in /var/www/zippy-test/vendor/alchemy/zippy/src/Zippy.php:160
Stack trace:
#0 /var/www/zippy-test/vendor/alchemy/zippy/src/Zippy.php(67): Alchemy\Zippy\Zippy->getAdapterFor('tar.gz')
#1 /var/www/zippy-test/web/index.php(18): Alchemy\Zippy\Zippy->create('test.tar.gz', 'testfiles/')
#2 {main}

Next exception 'Alchemy\Zippy\Exception\RuntimeException' with message 'Unable to create archive' in /var/www/zippy-test/vendor/alchemy/zippy/src/Zippy.php:70
Stack trace:
#0 /var/www/zippy-test/web/index.php(18): Alchemy\Zippy\Zippy->create('test.tar.gz', 'testfiles/')
#1 {main}
  thrown in /var/www/zippy-test/vendor/alchemy/zippy/src/Zippy.php on line 70

Better phpdoc comments

on AdapterInterface listMembers function documented as @return array
it is correct but @return MemberInterface[] would support better code completion.

Overwrite zip file members in doExtractMembers

Hi !

I'm starting using Zippy to handle zip files, thanks for the job by the way.
If I try to extract a file that already exists, it simply triggers an exception.

Is there any reason extraction of members doesn't have the overwrite option (-o) while the the doExtract does have it ?

Chunked archives

I couldn't find anything in the documentation, is there any way to create an archive split in chunks via Zippy ?

cannot create zip archive.

The doc says I can do this way:

<?php
$zippy = Zippy::load();
$zippy->create('archive.zip');

but this code throws an exception Unable to create archive from Zippy.php at line 63 and previous exception NotSupportedException: Can not create empty zip archive from ZipAdapter.php at line 51

Tag new version

It's been almost a year with no tag. I'm took over project where dev dependency is used, which is really bad idea, that might cause breaking thing per commit.

Could you please tag new version?

Can't create large zip/tar file

I am trying to create a large zip/tar file over 4GB. I know zip file has 4GB limitation. So, I tried tar archive. When I create an archive I get following exception: "Unable to launch a new process."

When I dug deep, I found that your library is adding all files (over 6000+) in a single command line.. Here is the command line:

"D:\cmder\vendor\msysgit\bin\tar.EXE" "--no-recursion" "-c" "--bzip2" "--file=d:\myfile.tar.bz2" "--no-recursion" "long-file-name.jpg" "long-file-name.jpg" "long-file-name.jpg"

Is it possible to add files in chunks instead of all together?

Issue with tar extension on Mac

Hi,

Here is the error when I use "tar" :

Unable to execute the following command '/usr/bin/bsdtar' '--create' '-' '--files-from /dev/null' '> /Users/vince/work/web/ps/designerbox/modules/invoices/invoices.tar' {output: bsdtar: Option --files-from /dev/null is not supported Usage: List: bsdtar -tf Extract: bsdtar -xf Create: bsdtar -cf [filenames...] Help: bsdtar --help }

I'm working on Mac with Mavericks (10.9), it looks like he doesnt like the "--files-from /dev/null" command

Tag a release

it would be great if version 0.2.0 could be released

Split zippy?

I'm using zippy in a symfony project, and I really like it.
But it really bloats the required dependencies, it installs pimple and guzzle, although I'm neither using pimple for configuration, nor guzzle for the teleport-stuff.
I'd love to see smaller packages for zippy, with the main archive functionality in zippy, and for example zippy-teleport-guzzle as an addon for the guzzle-teleporter, and maybe zippy-pimple for the driver configuration.
I didn't read into the teleporter-stuff very deeply, maybe even a package zippy-teleporter could be created, where the teleporter classes maintained? Don't know if the teleporter classes are used for regular archive handling...

I could provide a zippy-bundle for symfony integration, if someone is interested in this.

Unable to install platform2 laraveal package due to zippy error

Hi,

I experienced below issue while istalling, Kindly help to fix and install. Thank you.

E:\xampp\htdocs\vijay\service\new\my-platform2-project>composer install

  • Installing alchemy/zippy (dev-master 624e5d4)
    Downloading: 100%

    [UnexpectedValueException]
    'E:\xampp\htdocs\vijay\service\new\my-platform2-project\vendor/alchemy/zipp
    y/1089a8524e8e796241e8d00d36e46b2f' is not a zip archive.

Zippy::create() - blacklist support

It would be nice to have an option to blacklist specific files (e.g. .DS_Store) when adding paths to archive using Zippy::create() method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.