Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyperimpose/bencode
An erlang implementation of Bittorrent’s bencode format. See: http://bittorrent.org/beps/bep_0003.html
https://github.com/hyperimpose/bencode
bencode bencode-decoder bencode-encoder bencode-parser erlang erlang-libraries erlang-library erlang-otp
Last synced: 14 days ago
JSON representation
An erlang implementation of Bittorrent’s bencode format. See: http://bittorrent.org/beps/bep_0003.html
- Host: GitHub
- URL: https://github.com/hyperimpose/bencode
- Owner: hyperimpose
- License: other
- Created: 2024-04-14T11:40:42.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-04-16T22:41:41.000Z (10 months ago)
- Last Synced: 2024-11-19T21:33:54.199Z (3 months ago)
- Topics: bencode, bencode-decoder, bencode-encoder, bencode-parser, erlang, erlang-libraries, erlang-library, erlang-otp
- Language: Erlang
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: COPYING
Awesome Lists containing this project
README
* 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]].