1Convert::Bencode(3) User Contributed Perl Documentation Convert::Bencode(3)
2
3
4
6 Convert::Bencode - Functions for converting to/from bencoded strings
7
9 use Convert::Bencode qw(bencode bdecode);
10
11 my $string = "d4:ainti12345e3:key5:value4:type4:teste";
12 my $hashref = bdecode($string);
13
14 foreach my $key (keys(%{$hashref})) {
15 print "Key: $key, Value: ${$hashref}{$key}\n";
16 }
17
18 my $encoded_string = bencode($hashref);
19 print $encoded_string."\n";
20
22 This module provides two functions, "bencode" and "bdecode", which
23 encode and decode bencoded strings respectivly.
24
25 Encoding
26 "bencode()" expects to be passed a single value, which is either a
27 scalar, a arrary ref, or a hash ref, and it returns a scalar containing
28 the bencoded representation of the data structure it was passed. If the
29 value passed was a scalar, it returns either a bencoded string, or a
30 bencoded integer (floating points are not implemented, and would be
31 returned as a string rather than a integer). If the value was a array
32 ref, it returns a bencoded list, with all the values of that array also
33 bencoded recursivly. If the value was a hash ref, it returns a bencoded
34 dictionary (which for all intents and purposes can be thought of as a
35 synonym for hash) containing the recursivly bencoded key and value
36 pairs of the hash.
37
38 Decoding
39 "bdecode()" expects to be passed a single scalar containing the
40 bencoded string to be decoded. Its return value will be either a hash
41 ref, a array ref, or a scalar, depending on whether the outer most
42 element of the bencoded string was a dictionary, list, or a
43 string/integer respectivly.
44
46 The description of bencode is part of the bittorrent protocol
47 specification which can be found at
48 http://bitconjurer.org/BitTorrent/protocol.html
49
51 No error detection of bencoded data. Damaged input will most likely
52 cause very bad things to happen, up to and including causeing the
53 bdecode function to recurse infintly.
54
56 Created by R. Kyle Murphy <orclev@rejectedmaterial.com>, aka Orclev.
57
58 Copyright 2003 R. Kyle Murphy. All rights reserved. Convert::Bencode is
59 free software; you may redistribute it and/or modify it under the same
60 terms as Perl itself.
61
62
63
64perl v5.32.0 2020-07-28 Convert::Bencode(3)