module IO:High-order abstract I/O.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 -> char
No_more_input
if
no input available.val nread : input -> int -> string
nread 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
is n
< 0.val input : input -> string -> int -> int -> int
input 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 close_in : input -> unit
val write : 'a output -> char -> unit
val nwrite : 'a output -> string -> unit
val output : 'a output -> string -> int -> int -> int
output 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 flush : 'a output -> unit
val close_out : 'a output -> 'a
val input_string : string -> input
val output_string : unit -> string output
val input_channel : Pervasives.in_channel -> input
val output_channel : Pervasives.out_channel -> unit output
val input_enum : char Enum.t -> input
enum
.val output_enum : unit -> char Enum.t output
enum
. The
final enum is returned when the output is closed.val create_in : read:(unit -> char) ->
input:(string -> int -> int -> int) -> close:(unit -> unit) -> input
val create_out : write:(char -> unit) ->
output:(string -> int -> int -> int) ->
flush:(unit -> unit) -> close:(unit -> 'a) -> 'a output
val printf : 'a output -> ('b, unit, string, unit) format4 -> 'b
val read_all : input -> string
No_more_input
is raised.val pipe : unit -> input * unit output
Here is some API useful for working with binary files, in particular
binary files generated by C applications.
exception Overflow of string
val read_byte : input -> int
val read_ui16 : input -> int
val read_i16 : input -> int
val read_i32 : input -> int
Overflow
if the
read integer cannot be represented as a Caml 31-bit integer.val read_real_i32 : input -> int32
val read_double : input -> float
val read_string : input -> string
val read_line : input -> string
val write_byte : 'a output -> int -> unit
val write_ui16 : 'a output -> int -> unit
val write_i16 : 'a output -> int -> unit
val write_i32 : 'a output -> int -> unit
val write_real_i32 : 'a output -> int32 -> unit
val write_double : 'a output -> float -> unit
val write_string : 'a output -> string -> unit
val write_line : 'a output -> string -> 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