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.
nread i n reads a byte sequence 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.
really_nread i n reads a byte sequence 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.
input i b p l reads up to l characters from the given input, storing them in buffer b, 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 subsequence of b.
really_input i b p l reads exactly l characters from the given input, storing them in the buffer b, 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 subsequence of b.
output o b p l writes up to l characters from byte sequence b, 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 subsequence of b.
really_output o b p l writes exactly l characters from byte sequence b 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 subsequence of b.
Create an output that will write into a byte sequence in an efficient way. When closed, the output returns all the data written into it.
Sourceval output_strings : unit ->string listoutput
Create an output that will write into a string in an efficient way. When closed, the output returns all the data written into it. Several strings are used in case the output size excess max_string_length
You can safely transform any output to an unit output in a safe way by using this function.
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.
Drop up to 7 buffered bits and restart to next input character.
Generic IO Object Wrappers
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).