module IO:sig..end
IO module simply deals with abstract inputs/outputs. It provides a
set of methods for working with these IO as well as several
constructors that enable to write to an underlying channel, buffer,
or enum.
type input
type 'a output
'a is the accumulator data, it is returned
when the close_out function is called.exception No_more_input
read or
nread functions while there is no available token to read.exception Input_closed
exception Output_closed
val read : input -> charNo_more_input if
no input available.val nread : input -> int -> stringnread i n reads a string of size up to n from an input.
The function will raise No_more_input if no input is available.
It will raise Invalid_argument if n < 0.val really_nread : input -> int -> stringreally_nread i n reads a string of exactly n characters
from the input. Raises No_more_input if at least n characters are
not available. Raises Invalid_argument if n < 0.val input : input -> string -> int -> int -> intinput i s p l reads up to l characters from the given input, storing
them in string s, starting at character number p. It returns the actual
number of characters read or raise No_more_input if no character can be
read. It will raise Invalid_argument if p and l do not designate a
valid substring of s.val really_input : input -> string -> int -> int -> intreally_input i s p l reads exactly l characters from the given input,
storing them in the string s, starting at position p. For consistency with
IO.input it returns l. Raises No_more_input if at l characters are
not available. Raises Invalid_argument if p and l do not designate a
valid substring of s.val close_in : input -> unitval write : 'a output -> char -> unitval nwrite : 'a output -> string -> unitval output : 'a output -> string -> int -> int -> intoutput o s p l writes up to l characters from string s, starting at
offset p. It returns the number of characters written. It will raise
Invalid_argument if p and l do not designate a valid substring of s.val really_output : 'a output -> string -> int -> int -> intreally_output o s p l writes exactly l characters from string s onto
the the output, starting with the character at offset p. For consistency with
IO.output it returns l. Raises Invalid_argument if p and l do not
designate a valid substring of s.val flush : 'a output -> unitval close_out : 'a output -> 'aval input_string : string -> inputval output_string : unit -> string outputval output_strings : unit -> string list outputval input_channel : Pervasives.in_channel -> inputval output_channel : Pervasives.out_channel -> unit outputval input_enum : char Enum.t -> inputenum.val output_enum : unit -> char Enum.t outputenum. The
final enum is returned when the output is closed.val create_in : read:(unit -> char) ->
input:(string -> int -> int -> int) -> close:(unit -> unit) -> inputval create_out : write:(char -> unit) ->
output:(string -> int -> int -> int) ->
flush:(unit -> unit) -> close:(unit -> 'a) -> 'a outputval scanf : input -> ('a, 'b, 'c, 'd) Scanf.scannerval printf : 'a output -> ('b, unit, string, unit) Pervasives.format4 -> 'bval read_all : input -> stringNo_more_input is raised.val pipe : unit -> input * unit outputval pos_in : input -> input * (unit -> int)val pos_out : 'a output -> 'a output * (unit -> int)val cast_output : 'a output -> unit output
Here is some API useful for working with binary files, in particular
binary files generated by C applications. By default, encoding of
multibyte integers is low-endian. The BigEndian module provide multibyte
operations with other encoding.
exception Overflow of string
val read_byte : input -> intval read_signed_byte : input -> intval read_ui16 : input -> intval read_i16 : input -> intval read_i32 : input -> intOverflow if the
read integer cannot be represented as a Caml 31-bit integer.val read_real_i32 : input -> int32val read_i64 : input -> int64val read_float32 : input -> floatval read_double : input -> floatval read_string : input -> stringval read_line : input -> stringval write_byte : 'a output -> int -> unitval write_ui16 : 'a output -> int -> unitval write_i16 : 'a output -> int -> unitval write_i32 : 'a output -> int -> unitval write_real_i32 : 'a output -> int32 -> unitval write_i64 : 'a output -> int64 -> unitval write_float32 : 'a output -> float -> unitval write_double : 'a output -> float -> unitval write_string : 'a output -> string -> unitval write_line : 'a output -> string -> unitmodule BigEndian:sig..end
This enable you to read and write from an IO bit-by-bit or several bits
at the same time.
type in_bits
type out_bits
exception Bits_error
val input_bits : input -> in_bitsval output_bits : 'a output -> out_bitsval read_bits : in_bits -> int -> intval write_bits : out_bits -> nbits:int -> int -> unitval flush_bits : out_bits -> unitval drop_bits : in_bits -> unit
Theses OO Wrappers have been written to provide easy support of ExtLib
IO by external librairies. If you want your library to support ExtLib
IO without actually requiring ExtLib to compile, you can should implement
the classes in_channel, out_channel, poly_in_channel and/or
poly_out_channel which are the common IO specifications established
for ExtLib, OCamlNet and Camomile.
(see http://www.ocaml-programming.de/tmp/IO-Classes.html for more details).
class in_channel :input ->object..end
class out_channel :'a output ->object..end
class in_chars :input ->object..end
class out_chars :'a output ->object..end
val from_in_channel : #in_channel -> input
val from_out_channel : #out_channel -> unit output
val from_in_chars : #in_chars -> input
val from_out_chars : #out_chars -> unit output