Home

Awesome

Bencodex

A encode/decode library for bencoding

Bencode supports four types of objects

Decode Bencode terms into Elixir terms

Bencodex.decode("i1e")        # => 1
Bencodex.decode("3:foo")      # => "foo"
Bencodex.decode("li1e3:fooe") # => [1, "foo"]
Bencodex.decode("d3:fooi1ee") # => %{"foo" => 1}

Encode Elixir terms into Bencode terms

The accepted types are integer, binary (string), list and map

Bencodex.encode(1)             # => "i1e"
Bencodex.encode("foo")         # => "3:foo"
Bencodex.encode([1, "foo"])    # => "li1e3:fooe"
Bencodex.encode(%{"foo" => 1}) # => "d3:fooi1ee"