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 len reads up to len bytes from the given input, storing them in byte sequence s, starting at position p. It returns the actual number of bytes read or raise No_more_input if no character can be read. It will raise Invalid_argument if p and len do not designate a valid subsequence of s.
val really_input : input->Bytes.t->int ->int -> int
really_input i s p len reads exactly len characters from the given input, storing them in the byte sequence s, starting at position p. For consistency with BatIO.input it returns len.
output o s p len writes up to len characters from byte sequence len, starting at offset p. It returns the number of characters written. It will raise Invalid_argument if p and len do not designate a valid subsequence of s.
val output_substring : 'aoutput->string ->int ->int -> int
like output above, but outputs from a substring instead of a subsequence of bytes
since 2.8.0
val really_output : 'aoutput->Bytes.t->int ->int -> int
really_output o s p len writes exactly len characters from byte sequence s onto the the output, starting with the character at offset p. For consistency with BatIO.output it returns len.
raisesInvalid_argument
if p and len do not designate a valid subsequence of s.
val really_output_substring : 'aoutput->string ->int ->int -> int
like really_output above, but outputs from a substring instead of a subsequence of bytes
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.