module BatInnerIO:sig..end
This module contains the core definitions of BatIO, so as to avoid circular
dependencies between modules which only need simple functions of BatIO and
that module itself.
Don't use this module, use BatIO.
Author(s): Nicolas Cannasse, David Teller, Philippe Strauss, Edgar Friendly
type input
type 'a output
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 read_all : input -> stringNo_more_input is raised.val pipe : unit -> input * unit outputval 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.No_more_input if at least n characters are
not available.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
BatIO.input it returns l.No_more_input if at l characters are
not available.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
BatIO.output it returns l.Invalid_argument if p and l do not
designate a valid substring of s.val flush : 'a output -> unitval flush_all : unit -> unitval close_out : 'a output -> 'aval close_all : unit -> unitval input_string : string -> inputval output_string : unit -> string outputval on_close_out : 'a output -> ('a output -> unit) -> unitval create_in : read:(unit -> char) ->
input:(string -> int -> int -> int) ->
close:(unit -> unit) -> input
Note Do not use this function for creating an input
which reads from one or more underlying inputs. Rather, use
BatInnerIO.wrap_in.
val inherit_in : ?read:(unit -> char) ->
?input:(string -> int -> int -> int) ->
?close:(unit -> unit) -> input -> inputBatInnerIO.wrap_in whenever only
one input appears as dependency.val wrap_in : read:(unit -> char) ->
input:(string -> int -> int -> int) ->
close:(unit -> unit) -> underlying:input list -> input
This function is a more general version of BatInnerIO.create_in
which also handles dependency management between inputs.
val create_out : write:(char -> unit) ->
output:(string -> int -> int -> int) ->
flush:(unit -> unit) -> close:(unit -> 'a) -> 'a outputwrite : Write one character to the output (see BatInnerIO.write).output : Write a (sub)string to the output (see BatInnerIO.output).flush : Flush any buffers of this output (see BatInnerIO.flush).close : Close this output. The output will be automatically
flushed.
Note Do not use this function for creating an output which
writes to one or more underlying outputs. Rather, use BatInnerIO.wrap_out.
val inherit_out : ?write:(char -> unit) ->
?output:(string -> int -> int -> int) ->
?flush:(unit -> unit) ->
?close:(unit -> unit) -> 'a output -> unit outputBatInnerIO.wrap_out whenever only
one output appears as dependency.val wrap_out : write:(char -> unit) ->
output:(string -> int -> int -> int) ->
flush:(unit -> unit) ->
close:(unit -> 'a) ->
underlying:'b output list -> 'a output
This function is a more general version of BatInnerIO.create_out,
which also handles dependency management between outputs.
To illustrate the need for dependency management, let us consider the following values:
outf : _ output -> _ output, using BatInnerIO.create_out to
create a new output for writing some data to an underyling
output (for instance, a function comparale to tab_out or a
function performing transparent compression or transparent
traduction between encodings)f out is createdf out but not flushedout is closed, perhaps manually or as a consequence
of garbage-collection, or because the program has endedf out is flushed.out only after out has been closed,
which violates the protocol. Despite appearances, it is quite easy
to reach such situation, especially in short programs.
The solution is to use wrap_out rather than create_out in f.
Specifying that f out writes on out will then let the run-time
flush and close f out when out is closed for any reason, which
in turn avoids the issue.
write : Write one character to the output (see BatInnerIO.write).output : Write a (sub)string to the output (see BatInnerIO.output).flush : Flush any buffers of this output (see BatInnerIO.flush).close : Close this output. The output will be automatically
flushed.underlying : The list of outputs to which the new output will
write.
Note Function close should not close underlying
yourself. This is a common mistake which may cause sockets or
standard output to be closed while they are still being used by
another part of the program.
val default_buffer_size : int
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 an OCaml 31-bit integer.val read_real_i32 : input -> int32val read_i64 : input -> int64val read_float : 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_double : 'a output -> float -> unitval write_float : 'a output -> float -> unitval write_string : 'a output -> string -> unitval write_line : 'a output -> string -> unitval cast_output : 'a output -> unit outputval input_channel : ?autoclose:bool -> ?cleanup:bool -> Pervasives.in_channel -> inputautoclose : If true or unspecified, the BatInnerIO.input
will be automatically closed when the underlying in_channel
has reached its end.cleanup : If true, the channel
will be automatically closed when the BatInnerIO.input is closed.
Otherwise, you will need to close the channel manually.val output_channel : ?cleanup:bool -> Pervasives.out_channel -> unit outputcleanup : If true, the channel
will be automatically closed when the BatInnerIO.output is closed.
Otherwise, you will need to close the channel manually.val stdin : inputval stdout : unit output
Use this output to display regular messages.
val stderr : unit output
Use this output to display warnings and error messages.
val stdnull : unit output
Use this output to ignore messages.
The following modules may be useful to create hashtables of inputs or outputs.
module Input:sig..end
module Output:sig..end