theonedt / bencode

一个用于编码和解码 Bencode 数据的纯 PHP 库

dev-main 2021-03-09 19:52 UTC

This package is not auto-updated.

Last update: 2024-10-03 10:53:44 UTC


README

Codacy Badge FOSSA Status

Bencode 是 BitTorrent(https://open-source.org.cn/licenses/MIT)这种点对点文件共享系统用于存储和传输非结构化数据的编码方式。

这是一个纯 PHP 库,允许您编码和解码 Bencode 数据。

此库是从 [OPSnet/bencode-torrent] / [Rhilip/Bencode] (https://github.com/OPSnet/bencode-torrent) 分支出来的,方法和 sandfoxme/bencode 相似。

安装

composer require theonedt/bencode

使用方法

<?php

require '/path/to/vendor/autoload.php';

use Rhilip\Bencode\Bencode;
use Rhilip\Bencode\ParseErrorException;

// Decodes a BEncoded string
Bencode::decode(string $string);

// Encodes string/array/int to a BEncoded string
Bencode::encode(mixed $data);

// Decodes a BEncoded file From path
Bencode::load(string $path); 

// Encodes string/array/int to a BEncoded file
Bencode::dump(string $path, mixed $data); 

// With Error Catch
try {
    Bencode::decode('wrong_string');
 } catch (ParseErrorException $e) {
    // do something
} 

许可协议

此库根据 MIT 许可协议 作为开源库提供。

FOSSA Status