module OutputStream: sig
.. end
Output streams.
As stated in the class file format definition, multibyte data items are
always stored in big-endian order, where the high bytes come first.
Type
type
t
The type of output streams, whatever the stream destination is.
Exception
type
error =
| |
Unable_to_write_data |
| |
Unable_to_close_stream |
exception Exception of error
val string_of_error : error -> string
Constructors
val make_of_buffer : Buffer.t -> t
Creates an output stream whose destination is a buffer.
val make_of_channel : Pervasives.out_channel -> t
Creates an output stream whose destination is a channel.
val make_of_descr : Unix.file_descr -> t
Creates an input stream whose source is a file descriptor.
val make : write_byte:(int -> unit) ->
?write_bytes:(string -> int -> int -> unit) ->
flush:(unit -> unit) -> close:(unit -> unit) -> t
Creates an output stream from passed functions:
write
is used to write one byte (see Pervasives.output_byte
);
write_bytes src pos len
(optional) is used to write len
bytes from
src
, starting at index idx
;
flush
is used to flush the stream;
close
is used to close the stream.
Functions
val write_u1 : t -> Utils.u1 -> unit
Writes an unsigned 1-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_u2 : t -> Utils.u2 -> unit
Writes an unsigned 2-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_u4 : t -> Utils.u4 -> unit
Writes an unsigned 4-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_s1 : t -> Utils.s1 -> unit
Writes a signed 1-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_s2 : t -> Utils.s2 -> unit
Writes a signed 2-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_s4 : t -> Utils.s4 -> unit
Writes a signed 4-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_s8 : t -> Utils.s8 -> unit
Writes a signed 8-byte integer to the passed stream.
Raises Exception
if data cannot be written.
val write_bytes_from : t -> string -> int -> int -> unit
write_bytes_from s pos len st
writes len
bytes from s
starting at
pos
to st
. Raises Exception
if data cannot be written.
val write_bytes : t -> string -> unit
write_bytes s st
writes s
to st
.
Raises Exception
if data cannot be written.
val write_elements : ('a list -> Utils.u2) ->
t -> (t -> 'a -> unit) -> 'a list -> unit
write_elements length st f l
will first write to st
the
length of l
as a Utils.u2
value. Then, it will write the elements
from l
using f
. The parameter length
is used to determine the
length of l
, and should be used to ensure that the length fits in a
Utils.u2
value.
Raises Exception
if data cannot be written.
val flush : t -> unit
Flushes the passed stream.
Raises Exception
if an error occurs while flushing the stream.
val close : t -> unit
Closes the passed stream, any subsequent write will fail raising an exception.
Raises Exception
if an error occurs while closing the stream.
val close_noerr : t -> unit
Same as close
but raised exceptions are silently discarded.
val try_with : t -> (t -> 'a) -> 'a
try_with st f
is equivalent to Utils.try_finally st f close_noerr
.
Predefined streams
val stdout : t
Predefined stream for standard output.
val stderr : t
Predefined stream for standard error.