PHPackages                             bhutanio/torrent-bencode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. bhutanio/torrent-bencode

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

bhutanio/torrent-bencode
========================

PHP Library for decoding and encoding BitTorrent BEncoded data

332.7k14[1 issues](https://github.com/bhutanio/torrent-bencode/issues)[1 PRs](https://github.com/bhutanio/torrent-bencode/pulls)PHP

Since Sep 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bhutanio/torrent-bencode)[ Packagist](https://packagist.org/packages/bhutanio/torrent-bencode)[ RSS](/packages/bhutanio-torrent-bencode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Torrent BEncode
===============

[](#torrent-bencode)

PHP Library for decoding and encoding BitTorrent BEncoded data.

What is BEncode?
----------------

[](#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
------------

[](#requirements)

```
Apache or Nginx = Latest production version
PHP >= 5.3.0

```

Installation
------------

[](#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
-----

[](#usage)

### With Composer

[](#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

[](#without-composer)

```
	require 'path/to/BEncode.php';

	// use above example
```

Functions
---------

[](#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) {}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f8962bbd8caeec51e9510bf6bd39d84707e609d67a4f07191e0809f58b1f4c2?d=identicon)[abit.bt](/maintainers/abit.bt)

---

Top Contributors

[![abixalmon](https://avatars.githubusercontent.com/u/1712938?v=4)](https://github.com/abixalmon "abixalmon (11 commits)")[![MasterOdin](https://avatars.githubusercontent.com/u/1845314?v=4)](https://github.com/MasterOdin "MasterOdin (1 commits)")[![mihai-stancu](https://avatars.githubusercontent.com/u/1294142?v=4)](https://github.com/mihai-stancu "mihai-stancu (1 commits)")[![tboothman](https://avatars.githubusercontent.com/u/1813336?v=4)](https://github.com/tboothman "tboothman (1 commits)")

### Embed Badge

![Health badge](/badges/bhutanio-torrent-bencode/health.svg)

```
[![Health](https://phpackages.com/badges/bhutanio-torrent-bencode/health.svg)](https://phpackages.com/packages/bhutanio-torrent-bencode)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
