package octez-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/octez-libs.stdlib-unix/Tezos_stdlib_unix/Stored_data/index.html
Module Tezos_stdlib_unix.Stored_data
Source
Persistent data manager.
Every data read/write operation is protected by a mutex preventing concurrent data-races.
type 'a file = private {
encoding : 'a Data_encoding.t;
eq : 'a -> 'a -> bool;
path : string;
json : bool;
}
A data structure that represents files via their paths and encodings.
The type for the (persistent) data of a file.
This error is returned when the requested data is not found.
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
. eq
is used internally to test whether the contents of the file should be updated when calling write
or update_with
.
Warning It is the caller responsability to ensure that the base directory of the filepath
exists; otherwise, reading and writing will fail.
write data value
overwrites the previous data
with the new value
. The cache is only updated if the write succeeds. If the write fails, it is up to the user to retry.
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 avoiding data races. Favour the usage of write
.
val 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.
The cache is only updated if the write succeeds. If the write fails, it is up to the user to retry.
Warning Calling read/write in f
will result in a deadlock.
load encoded_file
loads and decode a data from an encoded_file
.
init encoded_file eq ~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.