Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Private.In_channel
SourceAlternate interface to Stdio.In_channel
. The create
and with_file
functions don't have a binary
option, so it is compatible with the Record_in_channel.Make
functor.
include module type of Stdio.In_channel
include Base.Equal.S with type t := t
Channels are opened in binary mode iff binary
is true. This only has an effect on Windows.
close t
closes t
, or does nothing if t
is already closed, and may raise an exception.
val really_input :
t ->
buf:Base.bytes ->
pos:Base.int ->
len:Base.int ->
Base.unit Base.option
Same as Pervasives.really_input
, for backwards compatibility
Read one character from the given input channel. Return None
if there are no more characters to read.
Same as input_char
, but return the 8-bit integer representing the character. Return None
if an end of file was reached.
Read an integer encoded in binary format (4 bytes, big-endian) from the given input channel. See Pervasives.output_binary_int
. Return None
if an end of file was reached while reading the integer.
Ocaml's built-in marshal format
input_buffer t buf ~len
reads at most len
characters from the input channel t
and stores them at the end of buffer buf
. Return None
if the channel contains fewer than len
characters. In this case, the characters are still added to the buffer, so as to avoid loss of data.
input_line ?fix_win_eol t
reads a line from t
and returns it, without the newline ("\n") character at the end, and, if fix_win_eol
the trailing "\r\n" 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
.
This works only for regular files. On files of other kinds, the behavior is unspecified.
Return the size (number of characters) of the regular file on which the given channel is opened. If the channel is opened on a file that is not a regular file, the result is meaningless. The returned size does not take into account the end-of-line translations that can be performed when reading from a channel opened in text mode.
same as Pervasives.set_binary_mode_in
, only applicable for Windows or Cygwin, no-op otherwise
read_lines filename
reads the full contents of file and returns it as a list of lines, closing the file when it's done. It's the equivalent of with_file fname ~f:input_lines
read_all filename
reads the full contents of file and returns it as a single string, closing the file when it's done. It's the equivalent of with_file fname ~f:input_all