package plebeia

  1. Overview
  2. Docs

1 Fixed size storage on a file

The Storage has fixed 32-byte size cells.

2 Types

type mode =
  1. | Private
    (*

    Private writer. The file is never modified. Modification to files by other writers may cause unspecified read result of Private.

    *)
  2. | Reader
    (*

    Reader

    *)
  3. | Writer
    (*

    Writer. Only one writer can exist.

    *)
type storage
type t = storage

The type

2 Open, close, and commit

val create : ?pos:int64 -> ?length:int -> ?resize_step:Plebeia__.Index.t -> string -> t

Create a new storage

* pos : Where to start the storage in the file, in bytes. * length: The initial size of the storage, excluding pos. * resize_step: How many cells allocated for each resize * string : The path name

val open_ : ?pos:int64 -> ?resize_step:Plebeia__.Index.t -> mode:mode -> string -> t

Open an existing storage

val truncate : ?length:int -> t -> unit

Truncate the data file and reinitialize it. All the contents are lost. length is the initial reserved size of the reinitialized file.

val sync : t -> unit

For reader to update the storage to catch up the update by the writer process. For Writer and Private, it does nothing.

val close : t -> unit

Close the storage

val commit : t -> unit

Write the current state of the storage at its header. If the system crashes, any updates to the storage after the last commit will be lost, even if they are written to the file.

2 Accessor

val filename : t -> string

Return the file name

val mode : t -> mode

Return the opening mode

val get_version : t -> int

Get the file version

val get_last_root_index : t -> Plebeia__.Index.t option
val get_current_length : t -> Plebeia__.Index.t

Get the status of the storage

For Reader, it only returns the lastest information it knows in memory. Writer may already update this information on the disk.

val size : t -> Int64.t

In bytes

val set_last_root_index : t -> Plebeia__.Index.t option -> unit

Set the last index of root hash. Note that the data are only saved to the file when Header.commit is called.

2 Read and write

val get_cell : t -> Plebeia__.Index.t -> Cstruct.t

Get the content of the cell specified by the index

val get_bytes : t -> Plebeia__.Index.t -> int -> Cstruct.t

Get the contiguous bytes from the head of the index

val new_index : t -> Plebeia__.Index.t

Allocate a cell and returns its index

val new_indices : t -> int -> Plebeia__.Index.t

Allocate cells and return the first index

val make_buf : t -> Plebeia__.Index.t -> Cstruct.t

make a writable buffer of the cell of the given index

val make_buf2 : t -> Plebeia__.Index.t -> Cstruct.t

make a 64 bytes writable buffer from the beginning of the cell of the given index

module Chunk : sig ... end

Bigger data than a cell

OCaml

Innovation. Community. Security.