Owl_io
read_file ?trim filename
reads the contents of the file specified by filename
and returns an array of strings, where each string represents a line from the file.
trim
: If set to true, leading and trailing whitespace from each line is removed.read_file_string filename
reads the entire contents of the file specified by filename
into a single string. Returns the contents of the file as a string.
write_file ?_flag filename content
writes the content
to the file specified by filename
.
_flag
: Optional file opening flag, such as Open_append
or Open_trunc
. The default behavior is to overwrite the file if it exists.marshal_from_file filename
deserializes data from the file specified by filename
using OCaml's Marshal module. Returns the deserialized data.
marshal_to_file ?flags data filename
serializes the data
and writes it to the file specified by filename
using OCaml's Marshal module.
flags
: Optional flags for controlling the serialization behavior.read_csv ?sep filename
reads a CSV file specified by filename
and returns a 2D array of strings, where each sub-array represents a row.
sep
: The character used to separate fields. The default separator is a comma (',').write_csv ?sep data filename
writes the 2D array of strings data
to the file specified by filename
in CSV format.
sep
: The character used to separate fields. The default separator is a comma (',').read_csv_proc ?sep f filename
processes each row of the CSV file specified by filename
using the function f
.
sep
: The character used to separate fields. The default separator is a comma (','). The function f
takes an index and a row (as a string array) as input.write_csv_proc ?sep data to_string filename
writes the 2D array of data data
to the file specified by filename
in CSV format.
sep
: The character used to separate fields. The default separator is a comma (','). The function to_string
is used to convert each element to a string.iteri_lines_of_file ?verbose f filename
iterates over each line of the file specified by filename
, applying the function f
to each line.
verbose
: If true, prints progress information. The default is false. The function f
takes the line index and the line content as input.mapi_lines_of_file f filename
maps the function f
over each line of the file specified by filename
, returning an array of results. The function f
takes the line index and the line content as input and returns a value of type 'a
.
iteri_lines_of_marshal ?verbose f filename
iterates over each line of serialized data in the file specified by filename
, deserializing it and applying the function f
.
verbose
: If true, prints progress information. The default is false. The function f
takes the line index and the deserialized data as input.mapi_lines_of_marshal f filename
maps the function f
over each line of serialized data in the file specified by filename
, deserializing it and returning an array of results. The function f
takes the line index and the deserialized data as input and returns a value of type 'b
.
head n filename
reads the first n
lines of the file specified by filename
and returns them as an array of strings.