In_channel
collects all of the pervasive functions that work on in_channels.
* It adds some new functions (like input_all
and input_lines
).
* It names things using the fact that there is no worry about toplevel name
conflicts (since we are in a module).
* It uses labelled arguments.
* It returns an option rather than raising End_of_file.
Note that an in_channel
is a custom block with a finalizer, and so is allocated
directly to the major heap. Creating a lot of in_channels can result in many major
collections and poor performance.
Channels are opened in binary mode iff binary
is true. This only has an effect on
Windows.
with_file ~f fname
executes ~f
on the open channel from
fname
, and closes it afterwards.
close t
closes t, and may raise an exception.
input_line ?fix_win_eol t
reads a line from t
and returns it, without
the newline ("
") character at the end, and, if fix_win_eol
the trailing
"
" is dropped.
fold_lines ?fix_win_eol t ~init ~f
folds over the lines read from t
using input_line
. Lines are provided to f
in the order they are
found in the file.
Completely reads an input channel and returns the results as a list of strings. Each line in one string.
iter_lines ?fix_win_eol t ~f
applies f
to each line read from t
using
input_line
.
same as Pervasives.set_binary_mode_in
, only applicable for Windows or Cygwin, no-op
otherwise