File_Bittorrent2
[ class tree: File_Bittorrent2 ] [ index: File_Bittorrent2 ] [ all elements ]

Class: File_Bittorrent2_Encode

Source Location: /File_Bittorrent2-1.3.1/File/Bittorrent2/Encode.php

Class Overview


Encode data in Bittorrent format


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 68]
Encode data in Bittorrent format

Based on Original Python implementation by Petru Paler <petru@paler.net> PHP translation by Gerard Krijgsman <webmaster@animesuki.com> Gerard's regular expressions removed by Carl Ritson <critson@perlfu.co.uk> BEncoding is a simple, easy to implement method of associating data types with information in a file. The values in a torrent file are bEncoded. There are 4 different data types that can be bEncoded: Integers, Strings, Lists and Dictionaries. [http://www.monduna.com/bt/faq.html]



[ Top ]


Method Detail

encode   [line 77]

string encode( mixed $mixed)

Encode a var in BEncode format
  • Throws: File_Bittorrent2_Exception if unsupported type should be encoded

Parameters:

mixed   $mixed   —  Variable to encode

[ Top ]

encode_array   [line 143]

string encode_array( array $array)

BEncodes an array This code assumes arrays with purely integer indexes are lists, arrays which use string indexes assumed to be dictionaries.

Dictionaries are prefixed with a d and terminated by an e. They are similar to list, except that items are in key value pairs. The dictionary {"key":"value", "Monduna":"com", "bit":"Torrents", "number":7} would bEncode to d3:key5:value7:Monduna3:com3:bit:8:Torrents6:numberi7ee

Lists are prefixed with a l and terminated by an e. The list should contain a series of bEncoded elements. For example, the list of strings ["Monduna", "Bit", "Torrents"] would bEncode to l7:Monduna3:Bit8:Torrentse. The list [1, "Monduna", 3, ["Sub", "List"]] would bEncode to li1e7:Mondunai3el3:Sub4:Listee


Parameters:

array   $array   — 

[ Top ]

encode_int   [line 119]

string encode_int( int $int)

BEncodes a integer

Integers are prefixed with an i and terminated by an e. For example, 123 would bEcode to i123e, -3272002 would bEncode to i-3272002e.


Parameters:

int   $int   — 

[ Top ]

encode_string   [line 104]

string encode_string( string $str)

BEncodes a string

Strings are prefixed with their length followed by a colon. For example, "Monduna" would bEncode to 7:Monduna and "BitTorrents" would bEncode to 11:BitTorrents.


Parameters:

string   $str   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:31:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.