Read and write bencode files in OCaml
type t =
| Integer of int64
| String of string
| List of t list
| Dict of (string * t) list
type src = [
| `Channel of Stdlib.in_channel
| `File_path of string
| `String of string
]
type dst = [
| `Channel of Stdlib.out_channel
| `File_path of string
| `Buffer of Stdlib.Buffer.t
]
val dict_of_list : (string * t) list -> t
sort list and wrap it in Dict
. The list should not contain the same key twice.
pretty_print
is not tail recursive (or pretty)
val pp_hum : Stdlib.Format.formatter -> t -> unit
pp_hum fmt tree
is the bencode tree
pretty-printed in a human-readable format on fmt
.
val pretty_print : t -> string
Simple pretty printer to strings
val decode : [< src ] -> t
encode
is not tail recursive
val encode : [< dst ] -> t -> unit
encode_to_string
is not tail recursive
val encode_to_string : t -> string
type 'a sequence = ('a -> unit) -> unit
Helpers
val as_string : t -> string option
val as_int : t -> int64 option
val as_list : t -> t list option
val as_dict : t -> (string * t) list option
val dict_get : t -> string -> t option