root/trunk/example.php
| Revision 84, 3.8 KB (checked in by m, 5 months ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | <?php |
| 2 | |
| 3 | // +----------------------------------------------------------------------+ |
| 4 | // | Decode and Encode data in Bittorrent format | |
| 5 | // +----------------------------------------------------------------------+ |
| 6 | // | Copyright (C) 2004-2005 Markus Tacker <m@tacker.org> | |
| 7 | // +----------------------------------------------------------------------+ |
| 8 | // | This library is free software; you can redistribute it and/or | |
| 9 | // | modify it under the terms of the GNU Lesser General Public | |
| 10 | // | License as published by the Free Software Foundation; either | |
| 11 | // | version 2.1 of the License, or (at your option) any later version. | |
| 12 | // | | |
| 13 | // | This library is distributed in the hope that it will be useful, | |
| 14 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 | // | Lesser General Public License for more details. | |
| 17 | // | | |
| 18 | // | You should have received a copy of the GNU Lesser General Public | |
| 19 | // | License along with this library; if not, write to the | |
| 20 | // | Free Software Foundation, Inc. | |
| 21 | // | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 22 | // +----------------------------------------------------------------------+ |
| 23 | |
| 24 | /** |
| 25 | * Example usage of File_Bittorrent |
| 26 | * |
| 27 | * @author Markus Tacker <m@tacker.org> |
| 28 | * @version $Id$ |
| 29 | */ |
| 30 | |
| 31 | /** |
| 32 | * Include class |
| 33 | */ |
| 34 | require_once 'File/Bittorrent/Encode.php'; |
| 35 | require_once 'File/Bittorrent/Decode.php'; |
| 36 | |
| 37 | $File_Bittorrent_Decode = new File_Bittorrent_Decode; |
| 38 | $File_Bittorrent_Encode = new File_Bittorrent_Encode; |
| 39 | |
| 40 | // Encoding vars |
| 41 | echo "Encoding integers\n"; |
| 42 | $encodedInt = $File_Bittorrent_Encode->encode(10); |
| 43 | var_dump($encodedInt); |
| 44 | var_dump($File_Bittorrent_Decode->decode($encodedInt)); |
| 45 | |
| 46 | echo "Encoding strings\n"; |
| 47 | $encodedStr = $File_Bittorrent_Encode->encode('This is a string.'); |
| 48 | var_dump($encodedStr); |
| 49 | var_dump($File_Bittorrent_Decode->decode($encodedStr)); |
| 50 | |
| 51 | echo "Encoding arrays as lists\n"; |
| 52 | $encodedList = $File_Bittorrent_Encode->encode(array('Banana', 'Apple', 'Cherry')); |
| 53 | var_dump($encodedList); |
| 54 | var_dump($File_Bittorrent_Decode->decode($encodedList)); |
| 55 | |
| 56 | echo "Encoding arrays as dictionaries\n"; |
| 57 | $encodedDict = $File_Bittorrent_Encode->encode(array('fruits' => array('Banana', 'Apple', 'Cherry','subarray' => array(1,2,3)), 'ints' => array(1,2,3), 'count' => 3)); |
| 58 | var_dump($encodedDict); |
| 59 | print_r($File_Bittorrent_Decode->decode($encodedDict)); |
| 60 | |
| 61 | // Decode a file |
| 62 | print_r($File_Bittorrent_Decode->decodeFile('install-x86-universal-2005.0.iso.torrent')); |
| 63 | |
| 64 | /* Output of decode |
| 65 | |
| 66 | Array |
| 67 | ( |
| 68 | [count] => 3 |
| 69 | [fruits] => Array |
| 70 | ( |
| 71 | [0] => Banana |
| 72 | [1] => Apple |
| 73 | [2] => Cherry |
| 74 | [subarray] => Array |
| 75 | ( |
| 76 | [0] => 1 |
| 77 | [1] => 2 |
| 78 | [2] => 3 |
| 79 | ) |
| 80 | |
| 81 | ) |
| 82 | |
| 83 | [ints] => Array |
| 84 | ( |
| 85 | [0] => 1 |
| 86 | [1] => 2 |
| 87 | [2] => 3 |
| 88 | ) |
| 89 | |
| 90 | ) |
| 91 | Array |
| 92 | ( |
| 93 | [name] => install-x86-universal-2005.0.iso |
| 94 | [filename] => install-x86-universal-2005.0.iso.torrent |
| 95 | [comment] => |
| 96 | [date] => 1111915968 |
| 97 | [created_by] => |
| 98 | [files] => Array |
| 99 | ( |
| 100 | [0] => Array |
| 101 | ( |
| 102 | [filename] => install-x86-universal-2005.0.iso |
| 103 | [size] => 712460288 |
| 104 | ) |
| 105 | |
| 106 | ) |
| 107 | |
| 108 | [size] => 712460288 |
| 109 | [announce] => http://titmouse.gentoo.org:6969/announce |
| 110 | [announce_list] => Array |
| 111 | ( |
| 112 | ) |
| 113 | |
| 114 | [info_hash] => f94b8d2d38632a6589d8121106059989f290b569 |
| 115 | ) |
| 116 | |
| 117 | */ |
| 118 | |
| 119 | ?> |
Note: See TracBrowser
for help on using the browser.