package tezos-stdlib-unix

  1. Overview
  2. Docs
Tezos: yet-another local-extension of the OCaml standard library (unix-specific fragment)

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-16.0.tar.gz
sha256=ad9e08819871c75ba6f4530b125f7d157799398e4d77a1e6bfea9d91ff37ff55
sha512=c5dc4d40cc09bc6980fbbdb5c2e105bf4252cf9cfcb2b49660b0ebe4dc789f6709ec3b3bf2f87d81580d3eed9521eeb1c960f24d9b14eb0285aaba1f84d10a9b

doc/tezos-stdlib-unix/Tezos_stdlib_unix/Stored_data/index.html

Module Tezos_stdlib_unix.Stored_dataSource

Persistent data manager.

Every data read/write operation is protected by a mutex preventing concurrent data-races.

Sourcetype 'a file = private {
  1. encoding : 'a Data_encoding.t;
  2. path : string;
  3. json : bool;
}

A data structure that represents files via their paths and encodings.

The type for the (persistent) data of a file.

Sourcetype 'a t

Note: This store uses the polymorphic equality on values.

Sourceval make_file : ?json:bool -> filepath:string -> 'a Data_encoding.t -> 'a file

make_file ?(json=false) ~filepath encoding represents a file located at filepath. The content of this value is encoded using encoding. By default, the content is encoded in binary content except if json=true.

Warning It is the caller responsability to ensure that the base directory of the filepath exists; otherwise, reading and writing will fail.

Sourceval get : 'a t -> 'a Lwt.t

get data accesses the data (cached).

Sourceval write : 'a t -> 'a -> unit Tezos_error_monad.Error_monad.tzresult Lwt.t

write data value overwrites the previous data with the new value. Note that if the write fails, The cache will have the new value (the one returned by get. It is recommended to reload a store in that case and try to write the value again.

Sourceval write_file : 'a file -> 'a -> unit Tezos_error_monad.Error_monad.tzresult Lwt.t

write_file encoded_file value raw writes the encoded_file with the value.

Warning this function should not be used in a normal context as it aims to overwrite the target without preserving data races. Favour the usage of write.

Sourceval update_with : 'a t -> ('a -> 'a Lwt.t) -> unit Tezos_error_monad.Error_monad.tzresult Lwt.t

update_with data f atomically updates data with the result of the application of f. Concurrent accesses to the data will block until the value is updated.

Warning Calling read/write in f will result in a deadlock.

load encoded_file loads and decode a data from an encoded_file.

Sourceval init : 'a file -> initial_data:'a -> 'a t Tezos_error_monad.Error_monad.tzresult Lwt.t

init encoded_file ~initial_data creates or load an on-disk data. If the file already exists, then the data is read from the file. Otherwise, initial_data is used.

OCaml

Innovation. Community. Security.