<?php /* * This file is part of the Bencoder package. * * (c) Daniele Alessandri <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/../autoload.php'; use Bencoder\Bencode; $torrent = Bencode::decodeFromFile(__DIR__ . '/../examples/xubuntu-10.10-alternate-amd64.iso.torrent'); // Remove info.pieces as it would print too much binary garbage. unset($torrent['info']['pieces']); var_dump($torrent);
/** * @group decoding */ public function testConversionToJSON() { $json = '{"a":1,"b":2,"list":[1,2,"foo","bar"]}'; $bencode = 'd1:ai1e1:bi2e4:listli1ei2e3:foo3:baree'; $this->assertSame($json, B::convertToJSON($bencode)); }
<?php /* * This file is part of the Bencoder package. * * (c) Daniele Alessandri <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/../autoload.php'; use Bencoder\Bencode; $structure = array('nickname' => 'nrk', 'letters' => array('n', 'r', 'k'), 'length' => 3); $encoded = Bencode::encode($structure); $decoded = Bencode::decode($encoded); var_dump($encoded); var_dump($decoded);