1Bencode(3)            User Contributed Perl Documentation           Bencode(3)
2
3
4

NAME

6       Bencode - BitTorrent serialisation format
7

VERSION

9       version 1.4
10

SYNOPSIS

12        use Bencode qw( bencode bdecode );
13
14        my $bencoded = bencode { 'age' => 25, 'eyes' => 'blue' };
15        print $bencoded, "\n";
16        my $decoded = bdecode $bencoded;
17

DESCRIPTION

19       This module implements the BitTorrent bencode serialisation format as
20       described in <http://www.bittorrent.org/protocol.html>.
21

INTERFACE

23   "bencode( $datastructure )"
24       Takes a single argument which may be a scalar or a reference to a
25       scalar, array or hash. Arrays and hashes may in turn contain values of
26       these same types. Simple scalars that look like canonically represented
27       integers will be serialised as such. To bypass the heuristic and force
28       serialisation as a string, use a reference to a scalar.
29
30       Croaks on unhandled data types.
31
32   "bdecode( $string [, $do_lenient_decode [, $max_depth ] ] )"
33       Takes a string and returns the corresponding deserialised data
34       structure.
35
36       If you pass a true value for the second option, it will disregard the
37       sort order of dict keys. This violation of the bencode format is
38       somewhat common.
39
40       If you pass an integer for the third option, it will croak when
41       attempting to parse dictionaries nested deeper than this level, to
42       prevent DoS attacks using maliciously crafted input.
43
44       Croaks on malformed data.
45

DIAGNOSTICS

47       "trailing garbage at %s"
48           Your data does not end after the first bencode-serialised item.
49
50           You may also get this error if a malformed item follows.
51
52       "garbage at %s"
53           Your data is malformed.
54
55       "unexpected end of data at %s"
56           Your data is truncated.
57
58       "unexpected end of string data starting at %s"
59           Your data includes a string declared to be longer than the
60           available data.
61
62       "malformed string length at %s"
63           Your data contained a string with negative length or a length with
64           leading zeroes.
65
66       "malformed integer data at %s"
67           Your data contained something that was supposed to be an integer
68           but didn't make sense.
69
70       "dict key not in sort order at %s"
71           Your data violates the bencode format constaint that dict keys must
72           appear in lexical sort order.
73
74       "duplicate dict key at %s"
75           Your data violates the bencode format constaint that all dict keys
76           must be unique.
77
78       "dict key is not a string at %s"
79           Your data violates the bencode format constaint that all dict keys
80           be strings.
81
82       "dict key is missing value at %s"
83           Your data contains a dictionary with an odd number of elements.
84
85       "nesting depth exceeded at %s"
86           Your data contains dicts or lists that are nested deeper than the
87           $max_depth passed to "bdecode()".
88
89       "unhandled data type"
90           You are trying to serialise a data structure that consists of data
91           types other than
92
93           ·   scalars
94
95           ·   references to arrays
96
97           ·   references to hashes
98
99           ·   references to scalars
100
101           The format does not support this.
102

BUGS AND LIMITATIONS

104       Strings and numbers are practically indistinguishable in Perl, so
105       "bencode()" has to resort to a heuristic to decide how to serialise a
106       scalar. This cannot be fixed.
107
108       Please report any bugs or feature requests through the web interface at
109       <http://github.com/ap/Bencode/issues>.
110

AUTHOR

112         Aristotle Pagaltzis <pagaltzis@gmx.de>
113
115       This software is copyright (c) 2010 by Aristotle Pagaltzis.
116
117       This is free software; you can redistribute it and/or modify it under
118       the same terms as the Perl 5 programming language system itself.
119
120
121
122perl v5.12.2                      2010-07-06                        Bencode(3)
Impressum