Git Product home page Git Product logo

archive7z's Introduction

Wrapper 7-zip (p7zip)

License Latest Stable Version Build Status Travis Build Status AppVeyor

Features:

  • Support all 7-zip formats: 7z, XZ, BZIP2, GZIP, TAR, ZIP, WIM, 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, VMDK, WIM, XAR and Z
  • Unpacking archives
  • Extract any directory or file
  • List files and directories
  • Get contents of any file from archive
  • Delete files or directories (not RAR)
  • Add files or directories (not RAR)

Requirements:

  • PHP >= 5.6
  • shell
  • 7-zip >= 7.30 (p7zip >= 9.38)

Installation:

composer require gemorroj/archive7z

Notes:

Recommendations:

Archive7z focuses on wrapping up the original 7-zip features. But it is not always convenient to use in your application. Therefore, we recommend that you always create your own wrapper class over Archive7z with the addition of higher-level logic.

Example:

<?php
use Archive7z\Archive7z;

class MyArchive7z extends Archive7z
{
    protected $timeout = 120;
    protected $compressionLevel = 6;
    protected $overwriteMode = self::OVERWRITE_MODE_S;
    protected $outputDirectory = '/path/to/custom/output/directory';
}

$obj = new MyArchive7z('path_to_7z_file.7z');

if (!$obj->isValid()) {
    throw new \RuntimeException('Incorrect archive');
}


foreach ($obj->getEntries() as $entry) {
        print_r($entry);
        /*
Archive7z\Entry Object
    (
        [path:Archive7z\Entry:private] => 1.jpg
        [size:Archive7z\Entry:private] => 91216
        [packedSize:Archive7z\Entry:private] => 165344
        [modified:Archive7z\Entry:private] => 2013-06-10 09:56:07
        [attributes:Archive7z\Entry:private] => A
        [crc:Archive7z\Entry:private] => 871345C2
        [encrypted:Archive7z\Entry:private] => +
        [method:Archive7z\Entry:private] => LZMA:192k 7zAES:19
        [block:Archive7z\Entry:private] => 0
        [comment:Archive7z\Entry:private] => 
        [hostOs:Archive7z\Entry:private] => 
        [folder:Archive7z\Entry:private] => 
        [archive:Archive7z\Entry:private] => Archive7z\Archive7z Object
            (
                [compressionLevel:protected] => 9
                [binary7z:Archive7z\Archive7z:private] => C:\Program Files\7-Zip\7z.exe
                [filename:Archive7z\Archive7z:private] => S:\VCS\Git\Archive7z\tests/fixtures/testPasswd.7z
                [password:Archive7z\Archive7z:private] => 123
                [outputDirectory:Archive7z\Archive7z:private] => ./
                [overwriteMode:Archive7z\Archive7z:private] => -aoa
                [timeout:Archive7z\Archive7z:private] => 60
            )

    )
         */

    if ($entry->getPath() === 'test/test.txt') {
        $entry->extractTo('path_to_extract_folder/'); // extract file
    }
}

echo $obj->getContent('test/test.txt'); // show content of the file
$obj->setOutputDirectory('path_to_extract_folder/')->extract(); // extract archive
$obj->setOutputDirectory('path_to_extract_pass_folder/')->setPassword('pass')->extractEntry('test/test.txt'); // extract password-protected entry

$obj->addEntry(__FILE__); // add file to archive
$obj->addEntry(__DIR__);  // add directory to archive (include subfolders)

$obj->renameEntry(__FILE__, __FILE__.'new'); // rename file in archive
$obj->delEntry(__FILE__.'new'); // remove file from archive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.