View Source jhn_bencoding (jhn_stdlib v5.3.2)

A Bencoding library based on: The BitTorrent specification

Bencoding is represented as follows:

Byte string : binary (octets) Integer : integer List : list Dictionary : map

Summary

Functions

Decodes the iodata into a structured Erlang term. Equivalent of decode(JSON, []) -> Term.

Decodes the iodata into a structured Erlang term. Options are: continue -> return the tuple of the decoded Bencoding and the remaining binary

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> Bencoding.

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> an iolist is returned (default)

Types

-type bencoding() :: binary() | integer() | list() | map().
-type opt() :: binary | iolist | continue.

Functions

-spec decode(binary()) -> bencoding().

Decodes the iodata into a structured Erlang term. Equivalent of decode(JSON, []) -> Term.

-spec decode(binary(), [opt()]) -> bencoding() | {bencoding(), binary()}.

Decodes the iodata into a structured Erlang term. Options are: continue -> return the tuple of the decoded Bencoding and the remaining binary

-spec encode(bencoding()) -> iolist().

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> Bencoding.

-spec encode(bencoding(), [opt()]) -> iolist() | binary().

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> an iolist is returned (default)