- Timestamp:
- 31.01.2005 13:43:23 (4 years ago)
- Location:
- trunk/File/Bittorrent
- Files:
-
- 2 modified
-
Decode.php (modified) (17 diffs)
-
Encode.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/File/Bittorrent/Decode.php
r4 r5 20 20 * Encode data in Bittorrent format 21 21 * 22 * Based on 22 * Based on 23 23 * Original Python implementation by Petru Paler <petru@paler.net> 24 24 * PHP translation by Gerard Krijgsman <webmaster@animesuki.com> … … 65 65 */ 66 66 var $name = ''; 67 67 68 68 /** 69 69 * @var string Filename of the torrent 70 70 */ 71 71 var $filename = ''; 72 72 73 73 /** 74 74 * @var string Comment 75 75 */ 76 76 var $comment = ''; 77 77 78 78 /** 79 79 * @var int Creation date as unix timestamp 80 80 */ 81 81 var $date = 0; 82 82 83 83 /** 84 84 * @var array Files in the torrent 85 85 */ 86 86 var $files = array(); 87 87 88 88 /** 89 89 * @var int Size of of the full torrent (after download) 90 90 */ 91 91 var $size = 0; 92 92 93 93 /** 94 94 * @var string Signature of the software which created the torrent 95 95 */ 96 96 var $created_by = ''; 97 97 98 98 /** 99 99 * @var string tracker (the tracker the torrent has been received from) … … 105 105 */ 106 106 var $announce_list = array(); 107 107 108 108 /** 109 109 * @var string Source string … … 111 111 */ 112 112 var $_source = ''; 113 113 114 114 /** 115 115 * @var int Current position of the string … … 117 117 */ 118 118 var $_position = 0; 119 119 120 120 /** 121 121 * Decode a Bencoded string … … 130 130 return $this->_bdecode(); 131 131 } 132 132 133 133 /** 134 134 * Decode .torrent file and accumulate information 135 135 * 136 * @param string Filename 136 * @param string Filename 137 137 * @return mixed Returns an arrayon success or false on error 138 138 */ … … 144 144 return false; 145 145 } 146 146 147 147 // Reset public attributes 148 148 $this->name = ''; … … 157 157 $this->_position = 0; 158 158 159 // Decode .torrent 159 // Decode .torrent 160 160 $this->_source = file_get_contents($file); 161 161 $decoded = $this->_bdecode(); 162 162 163 163 // Pull information form decoded data 164 164 $this->filename = basename($file); … … 177 177 $this->created_by = $decoded['created by']; 178 178 } 179 // There is sometimes an array listing all files 179 // There is sometimes an array listing all files 180 180 // in the torrent with their individual filesize 181 181 if (isset($decoded['info']['files']) and is_array($decoded['info']['files'])) { … … 207 207 } 208 208 } 209 209 210 210 // Currently, I'm not sure how to determine an error 211 211 // Just try to fetch the info from the decoded data … … 223 223 ); 224 224 } 225 225 226 226 /** 227 227 * Decode a BEncoded String … … 250 250 } 251 251 } 252 252 253 253 /** 254 254 * Decode a BEncoded dictionary … … 282 282 * @access private 283 283 * @return string 284 */ 284 */ 285 285 function _decode_string() 286 286 { … … 293 293 // Move Pointer after string 294 294 $this->_position = $pos_colon + $str_length + 1; 295 $return = utf8_decode($return); 295 296 return $return; 296 297 } 297 298 298 299 /** 299 300 * Decode a BEncoded integer … … 305 306 * @access private 306 307 * @return int 307 */ 308 */ 308 309 function _decode_int() 309 310 { … … 326 327 * @access private 327 328 * @return array 328 */ 329 */ 329 330 function _decode_list() 330 331 { … … 342 343 * 343 344 * @access private 344 * @return string 345 * @return string 345 346 */ 346 347 function _getChar() -
trunk/File/Bittorrent/Encode.php
r4 r5 20 20 * Encode data in Bittorrent format 21 21 * 22 * Based on 22 * Based on 23 23 * Original Python implementation by Petru Paler <petru@paler.net> 24 24 * PHP translation by Gerard Krijgsman <webmaster@animesuki.com> … … 58 58 * @param mixed Variable to encode 59 59 * @return string 60 */ 60 */ 61 61 function encode($mixed) 62 62 { … … 75 75 } 76 76 } 77 77 78 78 /** 79 79 * BEncodes a string … … 88 88 function encode_string($str) 89 89 { 90 $str = utf8_encode($str); 90 91 return sprintf('%d:%s', strlen($str), $str); 91 92 } 92 93 93 94 /** 94 95 * BEncodes a integer … … 105 106 return sprintf('i%de', $int); 106 107 } 107 108 108 109 /** 109 110 * BEncodes an array … … 120 121 * list of strings ["Monduna", "Bit", "Torrents"] would bEncode to 121 122 * l7:Monduna3:Bit8:Torrentse. The list [1, "Monduna", 3, ["Sub", "List"]] 122 * would bEncode to li1e7:Mondunai3el3:Sub4:Listee 123 * would bEncode to li1e7:Mondunai3el3:Sub4:Listee 123 124 * 124 125 * @param array … … 127 128 function encode_array($array) 128 129 { 130 // Sort array 131 asort($array, SORT_STRING); 129 132 // Check for strings in the keys 130 133 $isList = true;