bhittani/download

程序化下载文件、zip存档和GitHub仓库。

0.3.0 2022-02-18 07:05 UTC

This package is auto-updated.

Last update: 2024-09-18 12:45:21 UTC


README

程序化下载文件、zip存档和GitHub仓库。

需求

  • PHP >= 5.6
  • PHP Zip 扩展

安装

您可以使用composer安装此软件包。

$ composer require bhittani/download --prefer-dist

使用

此软件包当前允许下载/提取文件(本地/网络)、zip文件(本地/网络)和GitHub仓库。

下载文件

文件下载器允许从本地磁盘或通过网络下载单个文件。

<?php
use Bhittani\Download\File;

// Create an instance of Bhittani\Download\File with the path to the source file.
$file = new File('path/to/a/local/or/www/file.ext');

// Download the file to a local destination.
$file->download('path/to/local/destination/file.ext');

下载/解压zip存档

zip下载器允许从本地磁盘或通过网络下载zip文件,并将其内容解压到本地文件夹。

<?php
use Bhittani\Download\Zip;

// Create an instance of Bhittani\Download\Zip with path to the source zip archive.
$zip = new Zip('path/to/a/local/or/www/archive.zip');

// Download and extract the zip archive to a local destination.
$zip->download('path/to/local/destination/folder');

下载GitHub仓库

GitHub下载器允许将GitHub仓库下载到本地文件夹。

<?php
use Bhittani\Download\GitHub;

// Create an instance of Bhittani\Download\GitHub with the name of respository.
$gitHub = new GitHub('org/repo');

// Download the GitHub repository to a local destination.
$gitHub->download('path/to/local/destination/folder');

使用进度回调处理器

下载实例还接受进度回调。

$downloader = new \Bhittani\Download\GitHub('org/repo');

$downloader->callback(function ($transferred, $total, $time) {
    // $transferred will contain the number of bytes transferred.
    // $total will contain the total bytes.
    // $time will contain the time consumed in milliseconds.
});

$downloader->download('path/to/destionation/folder');

一个可调用的类Bhittani\Download\Progress\Standard提供了stdout进度回调,这可能对控制台输出很有用。

变更日志

有关更改的更多信息,请参阅CHANGELOG

测试

git clone https://github.com/kamalkhan/download

cd download

composer install

composer test

贡献

有关详细信息,请参阅CONTRIBUTINGCONDUCT

安全

如果您发现任何与安全相关的问题,请通过电子邮件shout@bhittani.com报告,而不是使用问题跟踪器。

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。