1. Overview
  2. Docs

File operations.

type fd

The type for open files, e.g. file descriptors.

val create_fd : read:(offset:int64 -> count:int -> Cstruct.t or_err) -> write:(offset:int64 -> Cstruct.t -> unit or_err) -> fd

Create an open file object.

val read : fd -> offset:int64 -> count:int -> Cstruct.t or_err

read f ~offset ~count reads an open file.

val write : fd -> offset:int64 -> Cstruct.t -> unit or_err

write f ~offset writes in a open file.

type t

The type for files.

val pp : t Fmt.t

pp is the pretty-printer for files.

val create : stat:(unit -> metadata or_err) -> open_:(unit -> fd or_err) -> remove:(unit -> unit or_err) -> truncate:(int64 -> unit or_err) -> chmod:(perm -> unit or_err) -> t

create is the file t such that FIXME.

val stat : t -> metadata or_err

stat t is t's metadata.

val size : t -> int64 or_err

size t is t's size.

val open_ : t -> fd or_err

open_ t if a file-descriptor for t.

val remove : t -> unit or_err

remove t removes t.

val truncate : t -> int64 -> unit or_err

truncate t len sets the length of t to len. If the new length is shorter, the file is truncated. If longer, it is padded with zeroes.

val chmod : t -> perm -> unit or_err

chmod t mode changes the mode of t.

Basic constructors

val ro_of_string : ?perm:perm -> string -> t

ro_of_string s is the static file containing s.

val rw_of_string : string -> t * (unit -> string)

rw_of_string init is a mutable file that initially contains init and a function which can be called to get the current contents.

val status : ?length:(unit -> int Lwt.t) -> (unit -> string Lwt.t) -> t

status f is the file containing the result of f. f is evaluated everytime the file is open. If length is not set, f will also be called during stat queries.

val command : ?init:string -> (string -> string or_err) -> t

command ?init f is the file containing the result of f. f is evaluated on every write, with the contents of the file as argument. Initially the file contains init.

K/V stores.

val of_kv : read:(unit -> Cstruct.t option or_err) -> write:(Cstruct.t -> unit or_err) -> stat:(unit -> metadata or_err) -> remove:(unit -> unit or_err) -> chmod:(perm -> unit or_err) -> t

of_kv ~read ~write ~remove ~stat interprets values from a k/v store as files. Handles reading and writing regions of the file.

val of_kvro : read:(unit -> Cstruct.t option or_err) -> stat:(unit -> metadata or_err) -> t

of_kvro is similar to of_kv but for read-only values.

val stat_of : read:(unit -> Cstruct.t option or_err) -> unit -> metadata or_err

stat_of ~read makes a stat function from read. The function reads the file to get the length, and reports the type as `Normal.


module Stream : sig ... end
val of_stream : (unit -> Stream.t Lwt.t) -> t

of_stream s is the file which will be, once opened, similar to the stream s ().


val err_no_entry : 'a or_err
val err_read_only : 'a or_err