Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
File operations on the stdlib in_channel
/out_channel
types
include FileSig.CONTENT_OPERATIONS
with type in_file := in_channel
and type out_file = out_channel
type out_file = out_channel
The type of a file to which we write: out_channel
for FileChannel
, string
for FileString
and FileGen.t
for FileGen
.
val read_file : in_channel -> string
read_file file
returns the full content of file
. If the file is opened, it is opened in binary mode, no conversion is applied.
val write_file : out_file -> string -> unit
write_file file content
creates file file
with content content
. If the file is opened, it is opened in binary mode, no conversion is applied.
val read_subfile : in_channel -> int -> int -> string
read_subfile file pos len
returns a string containing len
bytes read from file file
at pos pos
. If the file is opened, it is opened in binary mode. Raises End_of_file
if the file is too short.
val read_lines : in_channel -> string array
read_lines file
returns the content of file
as an array of lines. If the file is opened, it is opened in text mode.
val read_lines_to_list : in_channel -> string list
read_lines_to_list file
returns the content of file
as a list of lines. If the file is opened, it is opened in text mode.
val write_lines : out_file -> string array -> unit
write_lines file lines
creates the file file
from an array of lines, using FileChannel.output_line
for each line.
val write_lines_of_list : out_file -> string list -> unit
write_lines file lines
creates the file file
from a list of lines, using FileChannel.output_line
for each line.
val read_sublines : in_channel -> int -> int -> string array
read_sublines file pos len
returns at most len
lines of the file file
, starting at line pos
. It differs from read_subfile
in that it will not raise any exception if the file is too short. Note that it reads the file from beginning everytimes.
val read_sublines_to_list : in_channel -> int -> int -> string list
Same as read_sublines
, but returns a list of strings.
val iter_blocks : (EzCompat.Bytes.t -> int -> unit) -> in_channel -> unit
iter_blocks f file
reads the content of file file
, and calls f buffer len
on each chunk. The buffer
is reused, and only the first len
bytes are from the file. Chunks have a maximal size of 32768.
val iter_lines : (string -> unit) -> in_channel -> unit
iter_lines f file
calls f line
on all the lines line
of the file file
.
val iteri_lines : (int -> string -> unit) -> in_channel -> unit
iteri_lines f file
calls f line_num line
on every line line
of the file file
, with line_num
the line number, starting with line 0.
val copy_file : in_channel -> out_file -> unit
copy_file src dst
copy all the content remaining in file src
to file dst
.
val output_line : out_channel -> string -> unit