gocobachi/compressy

Compressy, the archive manager companion a child of the Alchemy/Zippy

dev-master 2021-01-26 08:11 UTC

This package is auto-updated.

Last update: 2024-04-26 15:33:15 UTC


README

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 Compressy in your project:

composer require gocobachi/compressy

Adapters

Compressy 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 Compressy is loaded and available as $compressy. You need the following code (or variation of) to load Compressy:

<?php

use Gocobachi\Compressy\Compressy;

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

// Load Compressy
$compressy = Compressy::load();

List an archive's contents:

// Open an archive
$archive = $compressy->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 = $compressy->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 = $compressy->create('archive.zip', [
    'folder' => '/path/to/directory'
], true);

Customize file and directory names inside archive

$archive = $compressy->create('archive.zip', [
    '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.

Extras

This project is a continuation of the Alchemy/Zippy package.