wapmorgan / unified-archive
UnifiedArchive - unified interface to all popular archive formats (zip, 7z, rar, gz, bz2, xz, cab, tar, tar.gz, tar.bz2, tar.xz, tar.Z, iso) for listing, reading, extracting and creation + built-in console archive manager + PclZip-like interface for zip archives.
Installs: 258 486
Dependents: 6
Suggesters: 1
Security: 0
Stars: 244
Watchers: 14
Forks: 19
Open Issues: 3
Requires
- php: >=5.5.0
- ext-fileinfo: *
Requires (Dev)
- docopt/docopt: ~1.0
- phpunit/phpunit: ~4.8
Suggests
- ext-bz2: BZ2 and TAR.BZ2 support
- ext-phar: TAR support
- ext-rar: RAR support
- ext-xz: XZ and TAR.XZ support
- ext-zip: ZIP support
- ext-zlib: GZ and TAR.GZ support
- bin-ncompress: TAR.Z support
- docopt/docopt: Requirement for cam (Console Archive Manager)
- gemorroj/archive7z: 7ZIP support
- pear/archive_tar: another TAR support
- phpclasses/php-iso-file: ISO support
- wapmorgan/cab-archive: CAB support
Replaces
- wapmorgan/cam: 1.0.2
README
UnifiedArchive - unified interface to all popular archive formats (zip # 7z # rar # gz # bz2 # xz # cab # tar # tar.gz # tar.bz2 # tar.x # tar.Z # iso) for listing, reading, extracting and creation + built-in console archive manager.
Contents:
- Preamble
- Functions
- Formats support
- Installation
- Usage
- API
- Built-in console archive manager
- Changelog
Preamble
If on your site/service there is a possibility of usage archives of many types, and you would like to work with them unified, you can use this library.
Functions
- Opening an archive with automatic format detection
- Getting information about uncompressed size of archive contents
- Listing archive content
- Getting details ([un]compressed size, date of modification) of every archived file
- Extracting archived file content as is or on a disk
- Reading archived file content as stream
- Adding files to archive
- Removing files from archive
- Creating new archives with files/directories
Simple usage
$archive = \wapmorgan\UnifiedArchive\UnifiedArchive::open('archive.zip'); $extracted_size = $archive->countUncompressedFilesSize(); $files_list = $archive->getFileNames(); echo 'Files list: '.array_map(function ($file) { return '- '.$file."\n"; }, $files_list).PHP_EOL; echo 'Total size after extraction: '.$extracted_size.' byte(s)';
Formats support
Formats | Driver | getFileContent() / getFileResource() | addFiles() / removeFiles() | archiveFiles() | Notes |
---|---|---|---|---|---|
.zip | extension: zip |
✔ | ✔ | ✔ | |
.7zip, .7z | package: gemorroj/archive7z AND 7zip-cli |
✔ / ✔ [1] | ✔ | ✔ | Uses system binary 7z to work |
.tar, .tar.gz, .tar.bz2, .tgz, .tbz2 | extension: phar |
✔ / ✔ [1] | ✔ | ✔ | Compressed versions of tar are supported by appropriate libraries or extensions (zlib for tab.gz, bzip2 for tab.bz2) |
.tar, .tar.gz, .tar.bz2, .tar.xz, .tar.Z, .tgz, .tbz2, .txz | package: pear/archive_tar |
✔ / ✔ [1] | ❌ | ✔ | Compressed versions of tar are supported by appropriate libraries or extensions (zlib for tab.gz, bzip2 for tab.bz2, xz for tab.xz) and installed software (ncompress for tar.Z) |
.rar | extension: rar |
✔ | ❌ | ❌ | |
.iso | package: phpclasses/php-iso-file |
✔ / ✔ [1] | ❌ | ❌ | |
.cab | package: wapmorgan/cab-archive |
✔[2] / ✔ [1][2] | ❌ | ❌ | Extraction is supported only on PHP 7.0.22+, 7.1.8+, 7.2.0. |
.gz | extension: zlib |
✔ | ✔ | ||
.bz2 | extension: bzip2 |
✔ | ✔ | ||
.xz | extension: lzma2 |
✔ | ✔ |
- [1] Simulation mode
- [2] Extraction ability depends on PHP version
Installation
Composer package: wapmorgan/unified-archive
- Add to composer.json
{ "require": { "wapmorgan/unified-archive": "^1.0.0" } }
Or run composer require wapmorgan/unified-archive
from your main package root folder.
Usage
Complex usage example of UnifiedArchive of described in Usage section.
API
Full API of UnifiedArchive is described in API document.
Changelog
To see all changes in library go to CHANGELOG file.
Built-in console archive manager
UnifiedArchive is distributed with a unified console program to manipulate popular
archive formats. This script is stored in vendor/bin/cam
.
It supports all formats that UnifiedArchive does and can be used to manipulate
archives without other software. To check your configuration and check formats
support launch it with -f
flag in console:
$ php vendor/bin/cam -f