BitTorrent's Bencode encoder/decoder

2.6.0 2021-02-14 14:14 UTC

This package is auto-updated.

Last update: 2021-06-03 20:11:23 UTC


Packagist PHP PHP Packagist Gitlab pipeline status Codecov

Bencode is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.

This is a pure PHP library that allows you to encode and decode Bencode data.


composer require 'sandfoxme/bencode'
  • Version 1.x supports PHP 7.0 and later
  • Version 2.x supports PHP 8.0 and later and has slightly better error handling

Simple use


\SandFox\Bencode\Bencode::encode(['info' => ['length' => 12345, 'name' => 'Bencoded demo']]);
\SandFox\Bencode\Bencode::decode('d4:infod6:lengthi12345e4:name13:Bencoded demoee');


Read full documentation here:

Documentation for earlier versions can be found on Read the Docs:


Please file issues on our main repo at GitLab:


The library is available as open source under the terms of the MIT License.