Module Stdio.In_channel
An input channel for doing blocking reads from input sources like files and sockets.
Note that an In_channel.t 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.
Note that this is simply another interface on the in_channel type in the OCaml standard library.
type t= Caml.in_channel
val stdin : t
val create : ?binary:Base.bool -> Base.string -> tval with_file : ?binary:Base.bool -> Base.string -> f:(t -> 'a) -> 'awith_file ~f fnameexecutes~fon the open channel fromfname, and closes it afterwards.
val close : t -> Base.unitclose tclosest, or does nothing iftis already closed, and may raise an exception.
val input : t -> buf:Base.bytes -> pos:Base.int -> len:Base.int -> Base.intval really_input : t -> buf:Base.bytes -> pos:Base.int -> len:Base.int -> Base.unit Base.optionval really_input_exn : t -> buf:Base.bytes -> pos:Base.int -> len:Base.int -> Base.unitSame as
Pervasives.really_input, for backwards compatibility
val input_char : t -> Base.char Base.optionRead one character from the given input channel. Return
Noneif there are no more characters to read.
val input_byte : t -> Base.int Base.optionSame as
input_char, but return the 8-bit integer representing the character. ReturnNoneif an end of file was reached.
val input_binary_int : t -> Base.int Base.optionRead an integer encoded in binary format (4 bytes, big-endian) from the given input channel. See
Pervasives.output_binary_int. ReturnNoneif an end of file was reached while reading the integer.
val unsafe_input_value : t -> _ Base.optionOcaml's built-in marshal format
val input_buffer : t -> Base.Buffer.t -> len:Base.int -> Base.unit Base.optioninput_buffer t buf ~lenreads at mostlencharacters from the input channeltand stores them at the end of bufferbuf. ReturnNoneif the channel contains fewer thanlencharacters. In this case, the characters are still added to the buffer, so as to avoid loss of data.
val input_all : t -> Base.stringval input_line : ?fix_win_eol:Base.bool -> t -> Base.string Base.optioninput_line ?fix_win_eol treads a line fromtand returns it, without the newline ("\n") character at the end, and, iffix_win_eolthe trailing "\r\n" is dropped.
val input_line_exn : ?fix_win_eol:Base.bool -> t -> Base.stringval fold_lines : ?fix_win_eol:Base.bool -> t -> init:'a -> f:('a -> Base.string -> 'a) -> 'afold_lines ?fix_win_eol t ~init ~ffolds over the lines read fromtusinginput_line. Lines are provided tofin the order they are found in the file.
val input_lines : ?fix_win_eol:Base.bool -> t -> Base.string Base.listCompletely reads an input channel and returns the results as a list of strings. Each line in one string.
val iter_lines : ?fix_win_eol:Base.bool -> t -> f:(Base.string -> Base.unit) -> Base.unititer_lines ?fix_win_eol t ~fappliesfto each line read fromtusinginput_line.
val seek : t -> Base.int64 -> Base.unitThis works only for regular files. On files of other kinds, the behavior is unspecified.
val pos : t -> Base.int64val length : t -> Base.int64Return 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.
val set_binary_mode : t -> Base.bool -> Base.unitsame as
Pervasives.set_binary_mode_in, only applicable for Windows or Cygwin, no-op otherwise
val read_lines : Base.string -> Base.string Base.listread_lines filenamereads the full contents of file and returns it as a list of lines, closing the file when it's done. It's the equivalent ofwith_file fname ~f:input_lines
val read_all : Base.string -> Base.stringread_all filenamereads the full contents of file and returns it as a single string, closing the file when it's done. It's the equivalent ofwith_file fname ~f:input_all