bhutanio/torrent-bencode
Composer 安装命令:
composer require bhutanio/torrent-bencode
包简介
PHP Library for decoding and encoding BitTorrent BEncoded data
README 文档
README
PHP Library for decoding and encoding BitTorrent BEncoded data.
What is BEncode?
Bencode (pronounced like B encode) is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.
It supports four different types of values:
- byte strings,
- integers,
- lists, and
- dictionaries (associative arrays).
Bencoding is most commonly used in torrent files. These metadata files are simply bencoded dictionaries.
While less efficient than a pure binary encoding, bencoding is simple and (because numbers are encoded as text in decimal notation) is unaffected by endianness, which is important for a cross-platform application like BitTorrent. It is also fairly flexible, as long as applications ignore unexpected dictionary keys, so that new ones can be added without creating incompatibilities.
Requirements
Apache or Nginx = Latest production version
PHP >= 5.3.0
Installation
Add this package in your composer.json and update composer.
{
"require": {
"bhutanio/torrent-bencode": "dev-master"
}
}
Update Composer
composer update or php composer.phar update
Usage
With Composer
require 'vendor/autoload.php'; $bcoder = new Bhutanio\BEncode; $bcoder->set([ 'announce'=>'http://www.private-tracker.com', 'comment'=>'Downloaded from Private Tracker', 'created_by'=>'PrivateTracker v1.0' ]); // decode Torrent file $torrent = $bcoder->bdecode( File::get('AwesomeMovie.torrent')); print_r($torrent); // show Torrent contents $files = $bcoder->filelist( $torrent ); print_r($files); // make Torrent private $torrent = $bcoder->make_private($torrent); print_r($torrent); $infohash = sha1($bcoder->bencode($torrent["info"])); $binhash = pack("H*", $bcoder->bencode($torrent["info"])));
Without Composer
require 'path/to/BEncode.php'; // use above example
Functions
/** * Data Setter * @param array $data [array of public variables] * eg: * $bcoder = new \Bhutanio\BEncode; * $bcoder->set([ * 'announce'=>'http://www.example.com', * 'comment'=>'Downloaded from example.com', * 'created_by'=>'TorrentSite v1.0' * ]); */ public function set($data=array()) {} /** * Decode a torrent file into Bencoded data * @param string $s [link to torrent file] * @param integer $pos [file position pointer] * @return array/null [Array of Bencoded data] * eg: * $bcoder = new \Bhutanio\BEncode; * $torrent = $bcoder->bdecode( File::get('MyAwesomeTorrent.torrent')); * var_dump($torrent); */ public function bdecode($s, &$pos=0) {} /** * Created Torrent file from Bencoded data * @param array $d [array data of a decoded torrent file] * @return string [data can be downloaded as torrent] */ public function bencode(&$d) {} /** * Decode a torrent file into Bencoded data * @param string $filename [File Path] * @return array/null [Array of Bencoded data] */ public function bdecode_file($filename) {} /** * Generate list of files in a torrent * @param array $data [array data of a decoded torrent file] * @return array [list of files in an array] */ public function filelist($data) {} /** * Replace array data on Decoded torrent data so that it can be bencoded into a private torrent file. * Provide the custom data using $this->set(); * @param array $data [array data of a decoded torrent file] * @return array [array data for torrent file] */ public function make_private($data) {}
bhutanio/torrent-bencode 适用场景与选型建议
bhutanio/torrent-bencode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.7k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2014 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bencode」 「encode」 「decode」 「bittorrent」 「torrent」 「bdecode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bhutanio/torrent-bencode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bhutanio/torrent-bencode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bhutanio/torrent-bencode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Encode integer IDs using a preset or customized symbol set
Runn Me! Serialization Library
Composer version of torrent-rw https://github.com/adriengibrat/torrent-rw
With the JSON codec you will be able to encode into and decode from JSON data in an object oriented way. It wraps PHP's functions `json_encode()` and `json_decode()`.
Microweber security scanner is a php antimalware/antivirus scanner script written in php for scan your project.
统计信息
- 总下载量: 2.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-08-10