mateuszanella/php-archive-stream 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mateuszanella/php-archive-stream

最新稳定版本:v1.0.2

Composer 安装命令:

composer require mateuszanella/php-archive-stream

包简介

A modular and lightweight PHP library for creating ZIP and TAR archives on-the-fly with streaming support.

README 文档

README

A modular and lightweight PHP library for creating ZIP and TAR archives on-the-fly with streaming support. Perfect for generating large archives without consuming excessive memory.

Features

  • 🚀 Stream-based archive creation (low memory usage)
  • 📦 Support for ZIP, TAR, and TAR.GZ formats
  • 🔧 Configurable compression and chunk sizes
  • 🌐 HTTP download support with proper headers
  • 📁 Multiple output destinations (file, HTTP, custom streams)
  • 🔌 Extensible architecture for custom formats

Installation

composer require mateuszanella/php-archive-stream

Quick Start

Basic Usage

To get started, include the library and create an ArchiveManager instance:

<?php

use PhpArchiveStream\ArchiveManager;

// Create a manager instance
$manager = new ArchiveManager;

Creating Archives

You can create different types of archives (ZIP, TAR, TAR.GZ) using the create method:

$zip = $manager->create('./archive.zip');
$tar = $manager->create('./archive.tar');
$tarGz = $manager->create('./archive.tar.gz');
$tarGz = $manager->create('./archive.tgz');

Adding Files

You can add files to the archive using various methods:

$archive->addFileFromPath('report.pdf', './reports/monthly.pdf');
$archive->addFileFromStream('data.json', fopen('./data.json', 'rb'));
$archive->addFileFromContentString('notes.txt', 'Important notes about the project.');

Finishing the Archive

To finalize the archive and write it to the destination, call the finish method:

$archive->finish();

HTTP Download

To stream the archive directly to the browser, you can create the archive with php://output as the destination:

// Stream directly to browser
$zip = $manager->create('php://output', 'zip');
$zip->addFileFromPath('report.pdf', './reports/monthly.pdf');
$zip->finish();

Multiple Destinations

You can specify multiple destinations for the archive by passing an array to the create method:

// Stream the archive to the browser and save a backup on disk
$zip = $manager->create([
    'php://output',
    './archive.zip'
]);
$zip->addFileFromPath('data.json', './data.json');
$zip->finish();

See more in the Usage Documentation.

Configuration

You can customize the behavior of the archive manager using a configuration array. This allows you to set options like chunk sizes, compression methods, and more.

See more in the Configuration Reference.

$config = [
    'zip' => [
        'enableZip64' => true,
        'input' => ['chunkSize' => 1048576], // 1MB chunks
    ],
    'tar' => [
        'input' => ['chunkSize' => 512], // 512B chunks
    ]
];

$manager = new ArchiveManager($config);

Documentation

For detailed documentation, configuration options, and advanced usage, see the documentation folder:

Requirements

  • PHP 8.3 or higher

License

MIT License. See LICENSE for details.

Contact

For questions, issues, or contributions, please open an issue on the GitHub repository, or email me at mateusblk1@gmail.com.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-25