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 := Stdlib.in_channel
and type out_file = Stdlib.out_channel
The type of a file to which we write: out_channel
for FileChannel
, string
for FileString
and FileGen.t
for FileGen
.
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.
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.
read_lines file
returns the content of file
as an array of lines. If the file is opened, it is opened in text mode.
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.
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.
Same as read_sublines
, but returns a list of strings.
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.
iter_lines f file
calls f line
on all the lines line
of the file file
.
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 : Stdlib.in_channel -> out_file -> unit
copy_file src dst
copy all the content remaining in file src
to file dst
.