Search documentation of jhn_stdlib

# jhn_bencoding (jhn_stdlib v5.10.3)

View Source

A Bencoding library based on: The BitTorrent specification

Bencoding is represented as follows:

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

# Summary

## Types

bencoding/0
opt/0

## Functions

decode(Binary)

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

decode(Binary, Opts)

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

encode(Term)

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

encode(Term, Opts)

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

# bencoding/0

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

# opt/0

    -type opt() :: binary | iolist | continue.

# Functions

# decode(Binary)

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

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

# decode(Binary, Opts)

    -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

# encode(Term)

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

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

# encode(Term, Opts)

    -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)