承接 esplora/decompresso 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

esplora/decompresso

Composer 安装命令:

composer require esplora/decompresso

包简介

PHP library for unlock contents from various files with ease.

README 文档

README

Tests Quality Assurance Coding Guidelines

Lumos is a library that provides a interface for removing passwords from protected documents and archives (extracting content), making these tasks simple and accessible.

What can I use this for?
  • Integrating with DLP platforms for protected file processing, ensuring compliance with corporate policies.
  • Unlock password-protected documents and archives for data extraction using tools like Apache Tika.
  • Utilize online services for removing passwords or recovering them through methods like brute force.

External Dependencies

Lumos uses the following third-party tools for operations. Each adapter is provided out of the box in the Esplora\Lumos\Adapters\* namespace:

File Type Tool Adapter Class
PDF qpdf QpdfAdapter
Microsoft Office msoffcrypto-tool MSOfficeCryptoToolAdapter
Archive (ZIP, 7z) 7-zip SevenZipAdapter
GnuPG (.gpg) gpg GpgAdapter
Email Message Format (.eml) cosmira/envelope EnvelopeAdapter

Installation

Install the library using Composer:

composer require esplora/lumos

Basic Usage

To get started, create an instance of the Extractor class and add the necessary adapters for file formats. The example below demonstrates using SevenZipAdapter for archive, but you can add your own adapters:

use Esplora\Lumos\Extractor;
use Esplora\Lumos\Adapters\SevenZipAdapter;

$lumos = Extractor::make([
    new SevenZipAdapter(),
])
    ->extract('/path/to/your/archive.zip');

$lumos->isSuccessful(); // true
$lumos->attempts(); // 1

Note

When multiple adapters are suitable for a given file, the first adapter in the list will be selected.

Handling Password-Protected Files

To work with password-protected documents, add a password provider. The example below uses ArrayPasswordProvider, which accepts an array of passwords.

use Esplora\Lumos\Extractor;
use Esplora\Lumos\Adapters\QpdfAdapter;
use Esplora\Lumos\Adapters\SevenZipAdapter;
use Esplora\Lumos\Adapters\MSOfficeCryptoToolAdapter;
use Esplora\Lumos\Providers\ArrayPasswordProvider;

$passwords = new ArrayPasswordProvider([
    'qwerty',
    'xxx123',
]);

Extractor::make()
    ->withAdapters([
        new QpdfAdapter(),
        new SevenZipAdapter(),
        new MSOfficeCryptoToolAdapter(),
    ])
    ->withPasswords($passwords)
    ->extract('/path/to/your/archive.zip', '/path/to/save/to')
    ->isSuccessful(); // false

If needed, you can create your own password provider by implementing the PasswordProviderInterface.

Tip

If you don’t have a password database but want to try all possible combinations, you can use SecLists as a source of popular passwords for brute-forcing.

Creating Custom Adapters

Lumos allows you to easily add support for new file types by creating custom adapters. To do so, implement a class that conforms to the Esplora\Lumos\Contracts\AdapterInterface.

Example of a custom adapter implementation:

namespace Esplora\Lumos\Adapters;

use Esplora\Lumos\Contracts\AdapterInterface;
use Esplora\Lumos\Contracts\PasswordProviderInterface;
use Esplora\Lumos\Results\SummaryInterface;

class CustomAdapter implements AdapterInterface
{
    /**
     * Checks if the adapter supports the given file.
     */
    public function canSupport(string $filePath): bool
    {
        return str_ends_with($filePath, '.custom');
    }

    /**
     * Checks if the environment is properly configured.
     */
    public function isSupportedEnvironment(): bool
    {
        return true; // Check external dependencies here
    }

    /**
     * Extracts the content to the specified directory.
     */
    public function extract(string $filePath, string $destination, PasswordProviderInterface $passwords): SummaryInterface
    {
        // Implement extraction logic here
    }
}

The library provides common tools to check if a specific file is supported using built-in traits:

To check based on the file's MIME type, use the trait SupportsMimeTypes:

use Esplora\Lumos\Concerns\SupportsMimeTypes;

class CustomAdapter implements AdapterInterface
{
    use SupportsMimeTypes;

    /**
     * Returns a list of supported MIME types.
     *
     * @return array<string> An array of supported MIME types.
     */
    protected function supportedMimeTypes(): array
    {
        return [
            'application/pdf', // Support for PDF files
            'image/jpeg',      // Support for JPEG images
        ];
    }

    // ...
}

To check based on file extensions, use the trait SupportsFileExtensions:

use Esplora\Lumos\Concerns\SupportsFileExtensions;

class CustomAdapter implements AdapterInterface
{
    use SupportsFileExtensions;

    /**
     * Returns a list of allowed file extensions.
     *
     * @return array<string> An array of allowed extensions.
     */
    protected function allowedExtensions(): array
    {
        return [
            'txt',  // Support for text files
            'zip',  // Support for ZIP archives
        ];
    }

    // ...
}

Testing

Testing an application that depends on other services can be challenging, but this should not prevent you from contributing to the project.

For adapters that depend on executable files, you can pass the path via the constructor:

use Esplora\Lumos\Adapters\SevenZipAdapter;

new SevenZipAdapter('/usr/bin/7z'),

For convenience, we also support using environment variables from a .env file to store paths to dependency executables in one place. To do this, create a .env file at the root of your project and add the environment variables as shown in the .env.example.

Warning

Environment variables from the .env file will be loaded only for local testing and are added solely for the convenience of developing this package.

Troubleshooting

Password Issues

Sometimes, the issue may be due to different encoding types, such as WINDOWS-CP1251 for Eastern Europe, while the software might input it as UTF-8. So, even if the password looks identical, it’s important to use the correct encoding.

Corrupted or Multipart Archive

The library doesn’t currently handle corruption detection or combining multipart archives. If the file is incompatible, the message will indicate that the password is incorrect.

esplora/decompresso 适用场景与选型建议

esplora/decompresso 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62 次下载、GitHub Stars 达 12, 最近一次更新时间为 2024 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「archives」 「extracting」 「decompression」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 esplora/decompresso 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 esplora/decompresso 我们能提供哪些服务?
定制开发 / 二次开发

基于 esplora/decompresso 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-19