Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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: #+BEGIN_SRC erlang {deps, [%% ... Other dependencies {bencode, {git, "https://github.com/hyperimpose/bencode.git", {branch, "master"}}}]}. #+END_SRC ** API Usage There are two functions exported by ~bencode~: decode/1 and encode/1. #+BEGIN_SRC erlang %% 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. #+END_SRC ** Term Mapping The bencoded values map to Erlang terms as follows: |--------------+--------------------------------------------------------------| | Bencode | Erlang | |--------------+--------------------------------------------------------------| | dictionaries | map() #{} (If there are duplicate keys the last one is kept) | | lists | list() [] (Including strings/iolists etc.) | | integers | integer() | | strings | binary() | |--------------+--------------------------------------------------------------| Atoms or other terms are not supported. ** License This implementation of bencode is licensed under the [[https://spdx.org/licenses/BSD-3-Clause.html][BSD 3-Clause "New" or "Revised" License]]. A copy of this license is included in the file [[./COPYING][COPYING]].