Bencode serialization for Laravel
![Software License][ico-license]
![Total Downloads][ico-downloads], (*1)
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., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require bhutanio/bencode, (*4)
## Usage
### Encoding an array
```php
<?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., (*5)
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:, (*6)
Array
(
[array] => Array
(
[0] => one
[1] => two
[2] => three
)
[integer] => 42
[string] => bar
)
Testing
bash
$ cp phpunit.xml.dst phpunit.xml
$ vendor/bin/phpunit -c phpunit.xml, (*7)
License
The MIT License (MIT). Please see License File for more information., (*8)