Zippy,归档管理器伴侣 - alchemy/zippy 的克隆版

v0.1.1 2024-07-11 14:30 UTC

This package is auto-updated.

Last update: 2024-09-11 14:53:42 UTC


README

License Packagist Travis Scrutinizer Packagist

一个用于通过命令行工具或 PHP 扩展读取、创建和提取各种格式的存档的 PHP 库

安装

唯一支持的安装方法是使用 Composer。运行以下命令将 Zippy 添加到您的项目中

composer require alchemy/zippy

适配器

Zippy 目前支持以下驱动程序和文件格式

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

入门

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

<?php

use Alchemy\Zippy\Zippy;

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

// Load Zippy
$zippy = Zippy::load();

列出存档内容

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

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

将存档提取到特定目录

// Open an archive
$archive = $zippy->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 = $zippy->create('archive.zip', array(
    'folder' => '/path/to/directory'
), true);

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

$archive = $zippy->create('archive.zip', array(
    '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 许可证