Module IO.Output

Output channel (byte sink)

include module type of struct include Iostream.Out_buf end
class type t = object ... end

An output stream, ie. a place into which we can write bytes, with a buffer to amortize the cost of operations.

class type t_seekable = object ... end
val create : ?flush:(unit -> unit) -> ?close:(unit -> unit) -> output_char:(char -> unit) -> output:(bytes -> int -> int -> unit) -> unit -> t

Create a new output stream from raw components.

class dummy : t
val dummy : t

Dummy output, drops everything written to it.

class virtual t_from_output : ?bytes:bytes -> unit -> object ... end

Make a bufferized output from a non bufferized output+close.

class bufferized : ?bytes:bytes -> Iostream.Out.t -> t
val bufferized : ?bytes:bytes -> Iostream.Out.t -> t
class of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable
val of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable

Wrap an out channel.

val of_buffer : Stdlib.Buffer.t -> t

of_buffer buf is an output channel that writes directly into buf. flush and close have no effect.

class open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> t_seekable
val open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> t_seekable

open_file file creates an out stream writing into the given file.

  • parameter mode

    permissions for the file creation

  • parameter flags

    set of unix flags to use. It must contain write permissions.

val with_open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> (t_seekable -> 'a) -> 'a
val output_char : t -> char -> unit

Output a single char

val output : t -> bytes -> int -> int -> unit

Write the slice of bytes.

val close : t -> unit

Close the stream. Idempotent.

val flush : t -> unit

Ensure the bytes written so far are indeed written to the underlying storage/network socket/… and are not just sitting in a buffer.

val output_string : t -> string -> unit

Output the whole string.

val output_line : t -> string -> unit

Output the whole string followed by '\n'.

  • since 0.2
val output_lines : t -> string Stdlib.Seq.t -> unit

Output a series of lines, each terminated by '\n'.

val output_int : t -> int -> unit

Output an integer in decimal notation.

val tee : t list -> t

tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.

val map_char : (char -> char) -> t -> t

Transform the stream byte by byte

class of_unix_fd : ?close_noerr:bool option -> closed:bool ref -> buf:Slice.t -> Unix.file_descr -> t
val output_buf : t -> Buf.t -> unit
val chunk_encoding : ?buf:Buf.t -> close_rec:bool -> t -> t

chunk_encoding oc makes a new channel that outputs its content into oc in chunk encoding form.

  • parameter close_rec

    if true, closing the result will also close oc

  • parameter buf

    a buffer used to accumulate data into chunks. Chunks are emitted when buf's size gets over a certain threshold, or when flush is called.