package tezos-stdlib-unix

  1. Overview
  2. Docs
val default_net_timeout : Ptime.Span.t ref

default_net_timeout is the default timeout used by functions in this library which admit a timeout value, i.e. read_bytes, Socket.connect, Socket.recv.

val read_bytes : ?timeout:Ptime.Span.t -> ?pos:int -> ?len:int -> Lwt_unix.file_descr -> bytes -> unit Lwt.t

read_bytes ?timeout ?pos ?len fd buf reads len-pos bytes from fd into bytes.

  • raises Lwt_unix.Timeout

    if the operation failed to finish within a timeout time span.

val write_string : ?pos:int -> ?len:int -> Lwt_unix.file_descr -> string -> unit Lwt.t
val write_bytes : ?pos:int -> ?len:int -> Lwt_unix.file_descr -> Bytes.t -> unit Lwt.t
val remove_dir : string -> unit Lwt.t
val create_dir : ?perm:int -> string -> unit Lwt.t
val read_file : string -> string Lwt.t
val create_file : ?close_on_exec:bool -> ?perm:int -> string -> string -> int Lwt.t
val with_tempdir : string -> (string -> 'a Lwt.t) -> 'a Lwt.t
val getaddrinfo : passive:bool -> node:string -> service:string -> (Ipaddr.V6.t * int) list Lwt.t
val getpass : unit -> string

getpass () reads a password from stdio while setting-up the terminal to not display the password being typed.

module Json : sig ... end
val retry : ?log:('error -> unit Lwt.t) -> ?n:int -> ?sleep:float -> (unit -> ('a, 'error) result Lwt.t) -> ('a, 'error) result Lwt.t
type 'action io_error = {
  1. action : 'action;
    (*

    action which triggerred the error.

    *)
  2. unix_code : Unix.error;
    (*

    Unix code error.

    *)
  3. caller : string;
    (*

    Unix function which triggerred the error.

    *)
  4. arg : string;
    (*

    Argument given to the unix function: generally a path.

    *)
}

with_io_error aims to be used as the error type for the with_* functions below. The action type is the action which trigerred the error.

val with_open_file : flags:Unix.open_flag list -> ?perm:Unix.file_perm -> string -> (Lwt_unix.file_descr -> 'a Lwt.t) -> ('a, [ `Open | `Close ] io_error) result Lwt.t

with_open_file ~flags ~perm filename f opens the given file using Lwt_unix.open_file and passes the resulting file-descriptor to f. with_open_file ensures that the file-descriptor is closed when the promise returned by f resolves, or if f raises an exception.

See Lwt_unix.openfile for a description of the arguments, warnings, and other notes. Default values for perm is 0o640.

Exceptions raised whilst opening or closing the file are wrapped in Error. When the error is `Open, the file could not be opened, and therefore the function f has not been run. When the error is `Closed, the function f was run but the file could not be closed.

Other exceptions are reraised.

val with_open_out : ?overwrite:bool -> string -> (Lwt_unix.file_descr -> 'a Lwt.t) -> ('a, [ `Open | `Close ] io_error) result Lwt.t

with_open_out ?overwrite filename f uses with_open_file with the flags O_WRONLY; O_CREAT; O_CLOEXEC and the default permissions. The flag O_TRUNC is added if overwrite is true, which is the case by default.

val with_atomic_open_out : ?overwrite:bool -> ?temp_dir:string -> string -> (Lwt_unix.file_descr -> 'a Lwt.t) -> ('a, [ `Open | `Close | `Rename ] io_error) result Lwt.t

with_atomic_open_out ?overwrite ?temp_dir filename f is a wrapper around with_open_out were it ensures that the data are written onto filename in an atomic way.

This function uses a temporary file stored in the temp_dir directory. Then, this temporary filed is renamed as filename.

The renaming may fail, for example if the temporary file is not on the same partition as filename.

If the renaming fails, an error `Rename is returned. See with_open_file for a description of the other errors. In that case, no write have been done on filename.

The default value of temp_dir is the same as Filename.temp_file.

val with_open_in : string -> (Lwt_unix.file_descr -> 'a Lwt.t) -> ('a, [ `Open | `Close ] io_error) result Lwt.t

with_open_in filename f uses with_open_file with the flags O_RDONLY; O_CLOEXEC and the default permissions.

OCaml

Innovation. Community. Security.