add IO.Out_channel.of_buffer

This commit is contained in:
Simon Cruanes 2023-07-18 13:57:12 -04:00
parent 355cc4d004
commit 29de702c55
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -79,6 +79,11 @@ module Out_channel = struct
close_out oc); close_out oc);
} }
(** [of_buffer buf] is an output channel that writes directly into [buf].
[flush] and [close] have no effect. *)
let of_buffer (buf : Buffer.t) : t =
{ output = Buffer.add_subbytes buf; flush = ignore; close = ignore }
(** Output the buffer slice into this channel *) (** Output the buffer slice into this channel *)
let[@inline] output (self : t) buf i len : unit = self.output buf i len let[@inline] output (self : t) buf i len : unit = self.output buf i len