File: README.md

package info (click to toggle)
matomo-component-decompress 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 444 kB
  • sloc: php: 3,125; makefile: 25; xml: 21
file content (96 lines) | stat: -rw-r--r-- 2,355 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Matomo/Decompress

Component providing several adapters to decompress files.

[![PHPUnit](https://github.com/matomo-org/component-decompress/actions/workflows/phpunit.yml/badge.svg)](https://github.com/matomo-org/component-decompress/actions/workflows/phpunit.yml)

It supports the following compression formats:

- Zip
- Gzip
- Bzip
- Tar (gzip or bzip)

With the following adapters:

- `PclZip`, based on the [PclZip library](http://www.phpconcept.net/pclzip/)
- `ZipArchive`, based on PHP's [Zip extension](http://fr.php.net/manual/en/book.zip.php)
- `Gzip`, based on PHP's native Gzip functions
- `Bzip`, based on PHP's native Bzip functions
- `Tar`, based on the [Archive_Tar library](https://github.com/pear/Archive_Tar) from PEAR

## Installation

With Composer:

```json
{
    "require": {
        "matomo/decompress": "^2.1"
    }
}
```

## Usage

All adapters have the same API as they implement `Matomo\Decompress\DecompressInterface`:

```php
// Extracting Gzip file
$extractor = new \Matomo\Decompress\Gzip('file.gz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Bzip file
$extractor = new \Matomo\Decompress\Bzip('file.bz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Zip file with ZipArchive
$extractor = new \Matomo\Decompress\ZipArchive('file.zip');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Zip file with PclZip
$extractor = new \Matomo\Decompress\PclZip('file.zip');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting .tar.bz2 file
$extractor = new \Matomo\Decompress\Tar('file.tar.bz2', 'bz2');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting .tar.gz file
$extractor = new \Matomo\Decompress\Tar('file.tar.gz', 'gz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}
```

## License

The Decompress component is released under the [LGPL v3.0](https://choosealicense.com/licenses/lgpl-3.0/).