diff --git a/dev/containers/CCIO/File/index.html b/dev/containers/CCIO/File/index.html index ac97d7db..6f0bf523 100644 --- a/dev/containers/CCIO/File/index.html +++ b/dev/containers/CCIO/File/index.html @@ -1,2 +1,2 @@ -File (containers.CCIO.File)

Module CCIO.File

type t = string

A file should be represented by its absolute path, but currently this is not enforced.

val to_string : t -> string
val make : string -> t

Build a file representation from a path (absolute or relative).

val exists : t -> bool
val is_directory : t -> bool
val remove_exn : t -> unit

remove_exn path tries to remove the file at path from the file system.

raises Sys_error

if there is no file at path or access rights are wrong.

since
0.8
val remove : t -> unit or_error

Like remove_exn but with an error monad.

since
0.8
val remove_noerr : t -> unit

Like remove_exn but do not raise any exception on failure.

since
0.8
val read_dir : ?⁠recurse:bool -> t -> t gen

read_dir d returns a sequence of files and directory contained in the directory d (or an empty stream if d is not a directory).

raises Sys_error

in case of error (e.g. permission denied).

parameter recurse

if true (default false), sub-directories are also explored.

val read_exn : t -> string

Read the content of the given file, or raises some exception.

raises Sys_error

in case of error.

since
0.16
val read : t -> string or_error

Read the content of the given file.

since
0.16
val append_exn : t -> string -> unit

Append the given string into the given file, possibly raising.

raises Sys_error

in case of error.

since
0.16
val append : t -> string -> unit or_error

Append the given string into the given file.

since
0.16
val write_exn : t -> string -> unit

Write the given string into the given file, possibly raising.

raises Sys_error

in case of error.

since
0.16
val write : t -> string -> unit or_error

Write the given string into the given file.

since
0.16
type walk_item = [ `File | `Dir ] * t
val walk : t -> walk_item gen

Like read_dir (with recurse=true), this function walks a directory recursively and yields either files or directories. Is a file anything that doesn't satisfy is_directory (including symlinks, etc.)

raises Sys_error

in case of error (e.g. permission denied) during iteration.

val walk_l : t -> walk_item list

Like walk but returns a list (therefore it's eager and might take some time on large directories).

since
1.1
val show_walk_item : walk_item -> string
val with_temp : ?⁠temp_dir:string -> prefix:string -> suffix:string -> (string -> 'a) -> 'a

with_temp ~prefix ~suffix f will call f with the name of a new temporary file (located in temp_dir). After f returns, the file is deleted. Best to be used in combination with with_out. See Filename.temp_file.

since
0.17
\ No newline at end of file +File (containers.CCIO.File)

Module CCIO.File

type t = string

A file should be represented by its absolute path, but currently this is not enforced.

val to_string : t -> string
val make : string -> t

Build a file representation from a path (absolute or relative).

val exists : t -> bool
val is_directory : t -> bool
val remove_exn : t -> unit

remove_exn path tries to remove the file at path from the file system.

raises Sys_error

if there is no file at path or access rights are wrong.

since
0.8
val remove : t -> unit or_error

Like remove_exn but with an error monad.

since
0.8
val remove_noerr : t -> unit

Like remove_exn but do not raise any exception on failure.

since
0.8
val read_dir : ?⁠recurse:bool -> t -> t gen

read_dir d returns a sequence of files and directory contained in the directory d (or an empty stream if d is not a directory).

raises Sys_error

in case of error (e.g. permission denied).

parameter recurse

if true (default false), sub-directories are also explored.

val read_exn : t -> string

Read the content of the given file, or raises some exception.

raises Sys_error

in case of error.

since
0.16
val read : t -> string or_error

Read the content of the given file.

since
0.16
val append_exn : t -> string -> unit

Append the given string into the given file, possibly raising.

raises Sys_error

in case of error.

since
0.16
val append : t -> string -> unit or_error

Append the given string into the given file.

since
0.16
val write_exn : t -> string -> unit

Write the given string into the given file, possibly raising.

raises Sys_error

in case of error.

since
0.16
val write : t -> string -> unit or_error

Write the given string into the given file.

since
0.16
type walk_item = [ `File | `Dir ] * t
val walk : t -> walk_item gen

Like read_dir (with recurse=true), this function walks a directory recursively and yields either files or directories. Is a file anything that doesn't satisfy is_directory (including symlinks, etc.)

raises Sys_error

in case of error (e.g. permission denied) during iteration.

val walk_iter : t -> walk_item iter

Like walk but with an imperative iterator.

since
NEXT_RELEASE
val walk_l : t -> walk_item list

Like walk but returns a list (therefore it's eager and might take some time on large directories).

since
1.1
val show_walk_item : walk_item -> string
val with_temp : ?⁠temp_dir:string -> prefix:string -> suffix:string -> (string -> 'a) -> 'a

with_temp ~prefix ~suffix f will call f with the name of a new temporary file (located in temp_dir). After f returns, the file is deleted. Best to be used in combination with with_out. See Filename.temp_file.

since
0.17
\ No newline at end of file diff --git a/dev/containers/CCIO/index.html b/dev/containers/CCIO/index.html index 88445576..b1de39fd 100644 --- a/dev/containers/CCIO/index.html +++ b/dev/containers/CCIO/index.html @@ -17,6 +17,6 @@ (fun oc -> write_gen oc chunks ) - ) ;;
since
0.6
before 0.12

was in 'containers.io', now moved into 'containers'

type 'a or_error = ('a, string) Stdlib.result
type 'a gen = unit -> 'a option

See Gen in the gen library.

Input

val with_in : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> 'a) -> 'a

Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.

raises Sys_error

in case of error (same as open_in and close_in).

parameter flags

opening flags (default [Open_text]). Open_rdonly is used in any cases.

val read_chunks_gen : ?⁠size:int -> Stdlib.in_channel -> string gen

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_chunks_seq : ?⁠size:int -> Stdlib.in_channel -> string Stdlib.Seq.t

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_line : Stdlib.in_channel -> string option

Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.

val read_lines_gen : Stdlib.in_channel -> string gen

Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_lines_seq : Stdlib.in_channel -> string Stdlib.Seq.t

Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_lines_l : Stdlib.in_channel -> string list

Read all lines into a list.

val read_all : ?⁠size:int -> Stdlib.in_channel -> string

Read the whole channel into a buffer, then converted into a string.

parameter size

the internal buffer size.

since
0.7
val read_all_bytes : ?⁠size:int -> Stdlib.in_channel -> Stdlib.Bytes.t

Read the whole channel into a mutable byte array.

parameter size

the internal buffer size.

since
0.12

Output

val with_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_in but for an output channel.

parameter flags

opening flags (default [Open_creat; Open_trunc; Open_text]).

raises Sys_error

in case of error (same as open_out and close_out). Open_wronly is used in any cases.

val with_out_a : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_out but with the [Open_append; Open_creat; Open_wronly] flags activated, to append to the file.

raises Sys_error

in case of error (same as open_out and close_out).

val write_line : Stdlib.out_channel -> string -> unit

Write the given string on the channel, followed by "\n".

val write_gen : ?⁠sep:string -> Stdlib.out_channel -> string gen -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

val write_seq : ?⁠sep:string -> Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

since
3.5
val write_lines : Stdlib.out_channel -> string gen -> unit

Write every string on the output, followed by "\n".

val write_lines_seq : Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write every string on the output, followed by "\n".

since
3.5
val write_lines_l : Stdlib.out_channel -> string list -> unit

Both

val with_in_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> Stdlib.out_channel -> 'a) -> 'a

Combines with_in and with_out.

parameter flags

opening flags (default [Open_creat]).

raises Sys_error

in case of error.

since
0.12
val copy_into : ?⁠bufsize:int -> Stdlib.in_channel -> Stdlib.out_channel -> unit

copy_into ic oc writes the content of ic into oc. It is a blocking call.

since
3.0

Misc for Generators

val tee : ('a -> unit) list -> 'a gen -> 'a gen

tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises

File and file names

How to list recursively files in a directory:

# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
+  ) ;;
since
0.6
before 0.12

was in 'containers.io', now moved into 'containers'

type 'a or_error = ('a, string) Stdlib.result
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option

See Gen in the gen library.

Input

val with_in : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> 'a) -> 'a

Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.

raises Sys_error

in case of error (same as open_in and close_in).

parameter flags

opening flags (default [Open_text]). Open_rdonly is used in any cases.

val read_chunks_gen : ?⁠size:int -> Stdlib.in_channel -> string gen

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_chunks_seq : ?⁠size:int -> Stdlib.in_channel -> string Stdlib.Seq.t

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_line : Stdlib.in_channel -> string option

Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.

val read_lines_gen : Stdlib.in_channel -> string gen

Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_lines_seq : Stdlib.in_channel -> string Stdlib.Seq.t

Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_lines_l : Stdlib.in_channel -> string list

Read all lines into a list.

val read_all : ?⁠size:int -> Stdlib.in_channel -> string

Read the whole channel into a buffer, then converted into a string.

parameter size

the internal buffer size.

since
0.7
val read_all_bytes : ?⁠size:int -> Stdlib.in_channel -> Stdlib.Bytes.t

Read the whole channel into a mutable byte array.

parameter size

the internal buffer size.

since
0.12

Output

val with_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_in but for an output channel.

parameter flags

opening flags (default [Open_creat; Open_trunc; Open_text]).

raises Sys_error

in case of error (same as open_out and close_out). Open_wronly is used in any cases.

val with_out_a : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_out but with the [Open_append; Open_creat; Open_wronly] flags activated, to append to the file.

raises Sys_error

in case of error (same as open_out and close_out).

val write_line : Stdlib.out_channel -> string -> unit

Write the given string on the channel, followed by "\n".

val write_gen : ?⁠sep:string -> Stdlib.out_channel -> string gen -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

val write_seq : ?⁠sep:string -> Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

since
3.5
val write_lines : Stdlib.out_channel -> string gen -> unit

Write every string on the output, followed by "\n".

val write_lines_seq : Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write every string on the output, followed by "\n".

since
3.5
val write_lines_l : Stdlib.out_channel -> string list -> unit

Both

val with_in_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> Stdlib.out_channel -> 'a) -> 'a

Combines with_in and with_out.

parameter flags

opening flags (default [Open_creat]).

raises Sys_error

in case of error.

since
0.12
val copy_into : ?⁠bufsize:int -> Stdlib.in_channel -> Stdlib.out_channel -> unit

copy_into ic oc writes the content of ic into oc. It is a blocking call.

since
3.0

Misc for Generators

val tee : ('a -> unit) list -> 'a gen -> 'a gen

tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises

File and file names

How to list recursively files in a directory:

# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
 # CCIO.write_lines stdout files;;

See File.walk if you also need to list directories:

# let content = CCIO.File.walk (CCIO.File.make "/tmp");;
 # Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
module File : sig ... end
\ No newline at end of file