codebites / cli-7zip
A wrapper for 7-zip CLI to compress, decompress and manipulate archives.
Installs: 415
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/codebites/cli-7zip
Requires
- php: >=8.2
- symfony/process: ^7.1
Requires (Dev)
- phpunit/phpunit: ^11.2
README
Description
This is a simple wrapper around the CLI binary of 7-zip. I tried to abstract the most commonly used commands like verify, extract, create and add. It will try to find the 7zz binary automatically on your system. I chose to use 7zz because it's statically linked and standalone thus perfect for shipping without any dependencies. You are also free to use other compatible binaries like 7zr or 7za by passing it to the constructor. If it can't find 7zz on your system, it will default to the bundled binary from the ./bin folder. I only bundle the Linux x86_64 for now. You also have the possibility to point to additional paths in which the library should look for the binary via the constructor of the Cli7zip class.
Because we use the full version we have support for all archive formats, not only .7z. Taken from the website of 7-zip it should support the following formats:
- Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM
- Unpacking only: APFS, AR, ARJ, CAB, CHM, CPIO, CramFS, DMG, EXT, FAT, GPT, HFS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RPM, SquashFS, UDF, UEFI, VDI, VHD, VHDX, VMDK, XAR and Z
Prerequisites
- PHP >= 8.2
Install
composer require codebites/cli-7zip
Usage
<?php use Codebites\Cli7zip\Cli7zip; // Init $cli7zip = new Cli7zip(); // Init with custom paths $cli7zip = new Cli7zip('7zz', ['/path/to/my/binaries_folder']); // Extract archive without folder creation $success = $cli7zip->extractArchive('/my/archive.7z', '/my/existing/target/folder'); // Extract archive with folder creation $success = $cli7zip->extractArchive('/my/archive.7z', '/my/non-existing/target/folder', true); // Compress directory as 7z $success = $cli7zip->compressDir('/my/folder/to/compress', '/my/archive.7z', '7z'); // Compress directory as Zip $archivePath = $cli7zip->compressDir('/my/folder/to/compress', '/my/archive.zip', 'zip'); // Add files to existing archive $success = $cli7zip->addFilesToArchive('/my/archive.7z', '/my/first/file.txt', '/my/seconde/file2.txt'); // Add string as file to existing archive $success = $cli7zip->addStringToArchive('/my/archive.7z', 'Hello, World!', 'filename.txt');
Warning
DO NOT USE IN PRODUCTION! This is highly experimental and not battle-tested. I wrote this for a use-case I had in about an hour. If there is any interest I will try to continue to improve this library.
License Information
This project includes binaries from 7-zip downloaded from Github. No modifications are made. The 7-zip binaries are distributed under the GNU Lesser General Public License (LGPL). The license is included in this repository.
- The 7-zip binaries are located in the
bindirectory. - The LGPL license can be found in
licenses/LGPL-3.0.txt.