Module Eris_lwt.Encoder

This module provides a streaming encoder that can be used to efficiently encode content piece-wise. The memory used is proportional to the level of the encoded content. The level is related logarithmicly to the size of the content.

type t

Type of an encoder

val init : convergence_secret:string -> block_size -> t

init ~convergence_secret block_size returns a new encoder.

val feed : t -> string -> (ref * block) list

feed encoder piece adds piece to the encoded content. Returns a list of reference and block pairs that can be emmited.

For every returned (ref, block) pair it holds that ref = Blake2b-256(block). As the hash is computed during encoding it is returned so that storage and transport layers do not have to recompute it.

There is no restriction on the size of piece. For best performance pieces should be the same size as the block size.

val finalize : t -> (ref * block) list * Read_capability.t

finalize encoder finishes encoding some content and returns remaing blocks as well as a read capability.