Skip to content

Repository files navigation

bencode

An erlang implementation of Bittorrent’s bencode format. See: http://bittorrent.org/beps/bep_0003.html

Notes and Warnings

  • There is no depth limit.
  • No error handing. Invalid input will cause a crash.

Build

This library can be built with rebar3: $ rebar3 compile

or you can include it in your projects as a dependency in rebar.config:

{deps, [%% ... Other dependencies
{bencode, {git, "https://github.com/hyperimpose/bencode.git", {branch, "master"}}}]}.

API Usage

There are two functions exported by bencode: decode/1 and encode/1.

%% Encode an erlang term:%%%% This function will return the following bencoded binary:%% <<"d4:testi123ee">>bencode:encode(#{<<"test"=>123>>}).
%% Decode an erlang term:%%%% This function will return an erlang dictionary:%% #{<<"test" => 123>>}bencode:decode(<<"d4:testi123ee">>).
%% See the next section for the supported terms and their equivalents.

Term Mapping

The bencoded values map to Erlang terms as follows:

BencodeErlang
dictionariesmap() #{} (If there are duplicate keys the last one is kept)
listslist() [] (Including strings/iolists etc.)
integersinteger()
stringsbinary()

Atoms or other terms are not supported.

License

This implementation of bencode is licensed under the BSD 3-Clause “New” or “Revised” License. A copy of this license is included in the file COPYING.

Releases

Used by

Contributors

Languages