bhutanio/bencode

Bencode serializer for Laravel

Installs: 887

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 3

Forks: 12

Open Issues: 0

pkg:composer/bhutanio/bencode

v2.0.3 2025-12-28 08:35 UTC

This package is auto-updated.

Last update: 2025-12-28 08:36:44 UTC


README

Latest Version on Packagist Software License Tests Total Downloads

This library allows developers to encode or decode bencoded data strings in Laravel. More information about bencode can be found at Wikipedia. The format is primarily used in the .torrent file specification.

Install

Via Composer

$ composer require bhutanio/bencode

Usage

Encoding an array

<?php

use Bhutanio\Bencode\Bencode;

$data = array(
    "string" => "bar",
    "integer" => 42,
    "array" => array(
        "one",
        "two",
        "three",
    ),
);

echo Bencode::encode($data);

The above produces the string d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare.

Decoding a string

<?php

use Bhutanio\Bencode\Bencode;

$string = "d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare";

print_r(Bencode::decode($string));

The above produces the the following output:

Array
(
    [array] => Array
        (
            [0] => one
            [1] => two
            [2] => three
        )

    [integer] => 42
    [string] => bar
)

Testing

$ composer install
$ vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.