gocobachi/compressy

Compressy,Alchemy/Zippy的档案管理器伴侣

dev-master 2021-01-26 08:11 UTC

This package is auto-updated.

Last update: 2024-09-26 16:16:36 UTC


README

License Packagist Travis Scrutinizer Packagist

A PHP库,通过命令行工具或PHP扩展在多种格式下读取、创建和提取存档

安装

唯一支持的安装方法是使用Composer。运行以下命令在项目中引入Compressy:

composer require gocobachi/compressy

适配器

Compressy目前支持以下驱动和文件格式

  • zip
    • .zip
  • PHP zip 扩展
    • .zip
  • GNU tar
    • .tar
    • .tar.gz
    • .tar.bz2
  • BSD tar
    • .tar
    • .tar.gz
    • .tar.bz2

入门指南

以下所有代码示例假设Compressy已经加载并作为$compressy可用。您需要以下代码(或其变体)来加载Compressy:

<?php

use Gocobachi\Compressy\Compressy;

// Require Composer's autoloader
require __DIR__ . '/vendor/autoload.php';

// Load Compressy
$compressy = Compressy::load();

列出存档的内容

// Open an archive
$archive = $compressy->open('build.tar');

// Iterate through members
foreach ($archive as $member) {
    echo "Archive contains $member" . PHP_EOL;
}

将存档提取到指定目录

// Open an archive
$archive = $compressy->open('build.tar');

// Extract archive contents to `/tmp`
$archive->extract('/tmp');

创建新的存档

// Creates an archive.zip that contains a directory "folder" that contains
// files contained in "/path/to/directory" recursively
$archive = $compressy->create('archive.zip', [
    'folder' => '/path/to/directory'
], true);

自定义存档内文件和目录的名称

$archive = $compressy->create('archive.zip', [
    'folder' => '/path/to/directory',            // will create a folder at root
    'http://www.google.com/logo.jpg',            // will create a logo.jpg file at root
    fopen('https://#/index.php'), // will create an index.php at root
    'directory/image.jpg' => 'image.jpg',        // will create a image.jpg in 'directory' folder
]);

文档

文档托管在read the docs

许可

该项目采用MIT许可证

附加信息

本项目是Alchemy/Zippy包的延续。