PHPackages                             samkitano/kompressor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. samkitano/kompressor

ActiveLibrary

samkitano/kompressor
====================

Basic compression tools for laravel

1.1.0(7y ago)07MITPHP

Since Dec 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/samkitano/Kompressor)[ Packagist](https://packagist.org/packages/samkitano/kompressor)[ RSS](/packages/samkitano-kompressor/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/70f42915b41d0f2f9ab212275029acd5731ed243a3c622a42b60f5bccbfbeb39/68747470733a2f2f7472617669732d63692e6f72672f73616d6b6974616e6f2f4b6f6d70726573736f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/samkitano/Kompressor)

An archive utility for Laravel 5.7
==================================

[](#an-archive-utility-for-laravel-57)

Kompressor is a simplified wrapper for PHP archive libraries, such as Zip, to easily manage archiving in Laravel.

REQUIREMENTS
------------

[](#requirements)

- PHP &gt;= 7.1.3
- Laravel 5.7.\*
- PHP [Zip extension](https://secure.php.net/manual/en/book.zip.php)

INSTALLATION
------------

[](#installation)

```
composer require samkitano/kompressor
```

CONFIGURATION
-------------

[](#configuration)

Publish configuration (optional):

```
php artisan vendor:publish --tag=kompressor
```

The configuration file contains detailed descriptions of all and each entry.

AVAILABLE ARCHIVING TOOLS
-------------------------

[](#available-archiving-tools)

At this time, only Zip is available. Feel free to implement your own archive tool.

USAGE
-----

[](#usage)

### Compress file(s)

[](#compress-files)

```
Kompressor::compress(
    $files,
    $destination = null,
    $name = null,
    $delete = false,
    $pattern = null
);
```

***Arguments***:

- **$files** \[array|string\] The file(s) or directory to archive

    - **required**
    - Must contain fully qualified path(s).
    - Can be a directory, a single file, or an array of files.
    - Multiple files must be on the same directory.
    - Multiple source directories are not allowed.
    - Mixed sources (directories and files) are not allowed.
- **$destination** \[string\] The destination path

    - **optional**
    - Overrides default configuration 'default\_archives\_directory'
    - If omitted, archive will be created on the default configuration.
    - If omitted and default configuration is not set, archive will be created on source directory.
    - Must be a fully qualified path.
    - Must exist.
- **$name** \[string\] The name for the archive file

    - **optional**
    - Default is source file(s) directory name.
    - No need to include extension.
- **$delete** \[boolean\] Mark the source file(s) for deletion after archiving

    - **optional**
    - Default value is false.
- **$pattern** \[string\] The *glob* search pattern for archiving directories

    - **optional**
    - Overrides default configuration 'glob\_dir\_pattern'
    - Default is '\*'

### Extract files

[](#extract-files)

```
Kompressor::extract(
    $source,
    $destination = null,
    $delete = false,
    $files = []
);
```

***Arguments***:

- **$source** \[string\] The full path to the archive

    - **required**
    - Must be a fully qualified path.
    - Archive must exist.
- **$destination** \[string\] The destination path

    - **optional**
    - If omitted, files will be extracted on the same archive directory.
    - Must be a fully qualified path.
    - Must exist.
- **$delete** \[boolean\] Mark the archive file for deletion after extraction

    - **optional**
    - Default value is false.
- **$files** \[array\] The specific file(s) to extract

    - **optional**
    - If omitted, all files will be extracted.
    - Must be an array of file names.
    - Must exist on archive.

Read an archive
---------------

[](#read-an-archive)

```
Kompressor::read(
    $source
);
```

***Arguments***:

- **$source** \[string\] The full path to the archive
    - **required**
    - Must be a fully qualified path.
    - Archive must exist.

Returns an array with the file names contained in the archive.

Add files into an archive
-------------------------

[](#add-files-into-an-archive)

```
Kompressor::add(
    $source,
    $files,
    $delete = false
);
```

***Arguments***

- **$source** \[string\] The full path to the archive

    - **required**
    - Must be a fully qualified path.
    - Archive must exist.
- **$files** \[array|string\] The file(s) or directory to add to the archive

    - **required**
    - Must be a single file, or an array of files.
    - Multiple files must be on the same directory.
    - Multiple source directories are not allowed.
    - Mixed sources (directories and files) are not allowed.
- **$delete** \[boolean\] Mark the source file(s) for deletion after adding to archive

    - **optional**
    - Default value is false.

### Remove files from archive

[](#remove-files-from-archive)

```
Kompressor::remove(
    $source,
    $files
);
```

***Arguments***

- **$source** \[string\] The full path to the archive

    - **required**
    - Must be a fully qualified path.
    - Archive must exist.
- **$files** \[array|string\] The file(s) to remove from the archive

    - **required**
    - Must be either a single file, or an array of files.
    - Multiple files must be on the same directory.
    - Multiple source directories are not allowed.
    - Mixed sources (directories and files) are not allowed.

ADDING SUPPORT FOR OTHER LIBRARIES
----------------------------------

[](#adding-support-for-other-libraries)

1 - Create a class within `libraries/`

- Class and file names **must** match the library name.
- Class **must** extend the *BaseCompression* class.
- Class **must** implement the *CompressionContract* interface.

For example, should you wish to implement the *gzip* library, class name should be **Gzip**, and file name should be **Gzip.php**

```
