Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
This module provides functions to read and write complete files from and to strings, or working on file lines.
The type of a file from which we read: in_channel
for FileChannel
, string
for FileString
and FileGen.t
for FileGen
.
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_file -> 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_file -> 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_file -> 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_file -> 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_file -> 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_file -> int -> int -> string list
Same as read_sublines
, but returns a list of strings.
val iter_blocks : (EzCompat.Bytes.t -> int -> unit) -> in_file -> 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_file -> unit
iter_lines f file
calls f line
on all the lines line
of the file file
.
val iteri_lines : (int -> string -> unit) -> in_file -> 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.