package bencode

  1. Overview
  2. Docs

Read and write bencode files in OCaml

type t =
  1. | Integer of int64
  2. | String of string
  3. | List of t list
  4. | Dict of (string * t) list
type src = [
  1. | `Channel of in_channel
  2. | `File_path of string
  3. | `String of string
]
type dst = [
  1. | `Channel of out_channel
  2. | `File_path of string
  3. | `Buffer of Buffer.t
]
val eq : t -> t -> bool
val hash : t -> int
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 : Format.formatter -> t -> unit

pp_hum fmt tree is the bencode tree pretty-printed in a human-readable format on fmt.

  • since 2.0
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
val decode_seq : [< src ] -> t sequence
val encode_seq : [< dst ] -> t sequence -> 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
OCaml

Innovation. Community. Security.