package octez-internal-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Io.UnixSource

Low level IO abstraction. A typical implementation is unix. This abstraction is meant to be dead simple. Not a lot of documentation is required.

It is not resistant to race condictions. There should not be concurrent modifications of the files.

These functions are essentially invoking the underlying functions from Unix directly; there is no buffering for example.

Sourcetype t

Errors

Sourcetype misc_error = Unix.error * string * string

An abstract error type that contains the IO-backend specific errors. (e.g. Unix.error)

Sourceval misc_error_t : misc_error Irmin.Type.t
Sourcetype create_error = [
  1. | `Io_misc of misc_error
  2. | `File_exists of string
]
Sourcetype open_error = [
  1. | `Io_misc of misc_error
  2. | `No_such_file_or_directory of string
  3. | `Not_a_file
]
Sourcetype read_error = [
  1. | `Io_misc of misc_error
  2. | `Read_out_of_bounds
  3. | `Closed
  4. | `Invalid_argument
]
Sourcetype write_error = [
  1. | `Io_misc of misc_error
  2. | `Ro_not_allowed
  3. | `Closed
]
Sourcetype close_error = [
  1. | `Io_misc of misc_error
  2. | `Double_close
]
Sourcetype mkdir_error = [
  1. | `Io_misc of misc_error
  2. | `File_exists of string
  3. | `No_such_file_or_directory of string
  4. | `Invalid_parent_directory
]

Safe Functions

None of the functions in this section raise exceptions. They may however perform effects that are always continued.

Life Cycle

Sourceval create : path:string -> overwrite:bool -> (t, [> create_error ]) Stdlib.result
Sourceval open_ : path:string -> readonly:bool -> (t, [> open_error ]) Stdlib.result
Sourceval close : t -> (unit, [> close_error ]) Stdlib.result

Write Functions

Sourceval write_string : t -> off:Optint.Int63.t -> string -> (unit, [> write_error ]) Stdlib.result

write_string t ~off s writes s at offset in t.

Sourceval fsync : t -> (unit, [> write_error ]) Stdlib.result

fsync t persists to the file system the effects of previous create or write.

Sourceval move_file : src:string -> dst:string -> (unit, [> `Sys_error of string ]) Stdlib.result
Sourceval copy_file : src:string -> dst:string -> (unit, [> `Sys_error of string ]) Stdlib.result
Sourceval mkdir : string -> (unit, [> mkdir_error ]) Stdlib.result

unlink_dont_wait file attempts to unlink the named file but doesn't wait for the completion of the unlink operation.

If unlink raises an exception it is passed to on_exn.

Read Functions

Sourceval read_to_string : t -> off:Optint.Int63.t -> len:int -> (string, [> read_error ]) Stdlib.result

read_to_string t ~off ~len are the len bytes of t at off.

Sourceval read_all_to_string : t -> (string, [> `Io_misc of misc_error | `Closed ]) Stdlib.result

read_to_string t is the contents full contents of the file.

The individual pages are not guaranteed to be read atomically.

Sourceval read_size : t -> (Optint.Int63.t, [> read_error ]) Stdlib.result

read_size t is the number of bytes of the file handled by t.

This function is expensive in the unix implementation because it performs syscalls.

Sourceval size_of_path : string -> (Optint.Int63.t, [> `Io_misc of misc_error | `No_such_file_or_directory of string | `Not_a_file ]) Stdlib.result
Sourceval classify_path : string -> [> `File | `Directory | `No_such_file_or_directory | `Other ]

MISC.

Sourceval readonly : t -> bool
Sourceval path : t -> string
Sourceval page_size : int

Unsafe Functions

These functions are equivalents to exising safe ones, but using exceptions instead of the result monad for performances reasons.

Sourceval read_exn : t -> off:Optint.Int63.t -> len:int -> bytes -> unit

read_exn t ~off ~len b reads the len bytes of t at off to b.

Raises Errors.Pack_error and Errors.RO_not_allowed.

Also raises backend-specific exceptions (e.g. Unix.Unix_error for the unix backend).

Sourceval write_exn : t -> off:Optint.Int63.t -> len:int -> string -> unit

write_exn t ~off ~len b writes the first len bytes pf b to t at offset off.

Raises Errors.Pack_error and Errors.RO_not_allowed.

Also raises backend-specific exceptions (e.g. Unix.Unix_error for the unix backend).

Sourceval raise_misc_error : misc_error -> 'a
Sourceval catch_misc_error : (unit -> 'a) -> ('a, [> `Io_misc of misc_error ]) Stdlib.result
OCaml

Innovation. Community. Security.