ZIP文件解析器和范围提取器

0.2.1 2022-10-05 17:11 UTC

This package is auto-updated.

Last update: 2024-09-05 21:29:00 UTC


README

The western cliffs with the stack of Arnamuil in the centre and Bagh na h-Aoineig to the left.

Tony Kinghorn / 西明谷悬崖 / CC BY-SA 2.0

概述

Mingulay是一个PHP库,用于从ZIP文件中解析文件信息。它搜索中央目录记录的结束,解析数据,然后使用这些数据检索包含ZIP文件中文件元数据的中央目录记录。

名字的由来?

明谷是我祖国苏格兰西海岸的赫布里底群岛中的一个岛屿,因此它似乎是一个合适的选择,因为这个库是在为群岛项目GitHub)做出贡献的过程中开发的。

安装

Mingulay可以通过Composer安装:composer require digitaldogsbody/mingulay,或者您也可以克隆仓库或从发行页面下载zip文件,并将src/目录的内容包含到您的项目中。

文档

一些基本的自动生成的PHPDoc文档可在GitHub页面上找到:https://digitaldogsbody.github.io/mingulay/。这些文档在每次对主分支进行提交时都会自动更新,因此应该总是与最新的代码保持一致。

版本控制

Mingulay遵循语义版本控制实践。在1.0.0版本发布之前,接口和功能应被视为不稳定且可能会更改。

用法

Mingulay需要一个实现Mingulay\SeekerInterface接口的对象。提供了LocalFileSeeker实现,用于在磁盘上处理ZIP文件。

$seeker = new \Mingulay\Seeker\LocalFileSeeker("test/fixtures/single-file.zip");
$zip_info = new \Mingulay\ZipRangeReader($seeker);
var_dump($zip_info->files);
array(1) {
  'README.md'=>
  array(6) {
    ["file_name"]=>
    string(9) "README.md"
    ["offset"]=>
    int(0)
    ["compressed_size"]=>
    int(43)
    ["uncompressed_size"]=>
    int(43)
    ["CRC32"]=>
    string(8) "C6E036CC"
    ["comment"]=>
    string(0) ""
  }
}

可以使用getStream()函数获取检索单个解压缩文件的指针

$seeker = new \Mingulay\Seeker\LocalFileSeeker("test/fixtures/multiple-files.zip");
$zip_info = new \Mingulay\ZipRangeReader($seeker);
$fp = $zip_info->getStream("LICENSE");
$local_fp = fopen("/tmp/example", "wb");
while(!feof($fp)) {
    fwrite($local_fp, fread($fp, 2048));
}
fclose($local_fp);
fclose($fp);

致谢和感谢

许可证

AGPL-3