package extlib
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=43fb3bf2989671af1769147b1171d080
sha512=dedd2bb4a63f2df9e451dbe6aede18d873489a8675f48ded09131f2af4d00dbeaecc8750039b2e4facb9f5f9b1b01c6b7accd392bf8ac5a3f2c801562ce5c4ee
doc/extlib/IO/index.html
Module IOSource
High-order abstract I/O.
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.
The abstract input type.
The abstract output type, 'a is the accumulator data, it is returned when the close_out function is called.
This exception is raised when reading on an input with the read or nread functions while there is no available token to read.
This exception is raised when reading on a closed input.
This exception is raised when reading on a closed output.
Standard API
Read a single char from an input or raise No_more_input if no input available.
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.
Close the output and return its accumulator data. It can no longer be written.
Creation of IO Inputs/Outputs
Create an output that will write into a string in an efficient way. When closed, the output returns all the data written into it.
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.
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
Create an input that will read from a channel.
Create an output that will write into a channel.
Create an output that will write into an enum. The final enum is returned when the output is closed.
val create_in :
read:(unit -> char) ->
input:(Bytes.t -> int -> int -> int) ->
close:(unit -> unit) ->
inputFully create an input by giving all the needed functions.
val create_out :
write:(char -> unit) ->
output:(Bytes.t -> int -> int -> int) ->
flush:(unit -> unit) ->
close:(unit -> 'a) ->
'a outputFully create an output by giving all the needed functions.
Utilities
The scanf function works for any input.
The printf function works for any output.
read all the contents of the input until No_more_input is raised.
Create a pipe between an input and an ouput. Data written from the output can be read from the input.
Create an input that provide a count function of the number of Bytes.t read from it.
Create an output that provide a count function of the number of Bytes.t written through it.
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.
Exception raised when a read or write operation cannot be completed.
Read a signed 32-bit integer. Raise Overflow if the read integer cannot be represented as an OCaml 31-bit integer.
Read a signed 32-bit integer, represented as OCaml integer, wrapping around 31-bit int on 32-bit architecture
Read an IEEE single precision floating point value (32 bits).
Write an IEEE single precision floating point value (32 bits).
Write an IEEE double precision floating point value (64 bits).
Write a byte sequence and append an null character.
Write a line and append a LF (it might be converted to CRLF on some systems depending on the underlying IO).
Bits API
This enable you to read and write from an IO bit-by-bit or several bits at the same time.
Write up to 31 bits represented as a value, raise Bits_error if nbits < 0 or nbits > 31 or the value representation excess nbits.
Flush remaining unwritten bits, adding up to 7 bits which values 0.
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).