Legend:
Library
Module
Module type
Parameter
Class
Class type
Core of the BatIO module.
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.
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 if n < 0.
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 really_input : input->string ->int ->int -> int
really_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.
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 really_output : 'aoutput->string ->int ->int -> int
really_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.
raisesInvalid_argument
if p and l do not designate a valid substring of s.
Fully create an output that writes to one or more underlying outputs.
This function is a more general version of create_out, which also handles dependency management between outputs.
To illustrate the need for dependency management, let us consider the following values:
an output out
a function f : _ output -> _ output, using 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)
With these values, let us consider the following scenario
a new output f out is created
some data is written to f out but not flushed
output out is closed, perhaps manually or as a consequence of garbage-collection, or because the program has ended
data written to f out is flushed.
In this case, data reaches 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.
Close this output. The output will be automatically flushed.
parameterunderlying
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
The default size of buffers.
Binary files API
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.
exceptionOverflowof string
Exception raised when a read or write operation cannot be completed.