diff --git a/src/Tiny_httpd_html.ml b/src/Tiny_httpd_html.ml
index ea8c56d3..5f781c87 100644
--- a/src/Tiny_httpd_html.ml
+++ b/src/Tiny_httpd_html.ml
@@ -19,7 +19,8 @@ include Tiny_httpd_html_
let to_out_channel ?(top = false) (self : elt) (out : IO.Out_channel.t) : unit =
let out = Out.create_of_out out in
if top then Out.add_string out "\n";
- self out
+ self out;
+ Out.flush out
(** Convert a HTML element to a string.
@param top if true, add DOCTYPE at the beginning. The top element should then
@@ -50,6 +51,13 @@ let to_string_top = to_string ~top:true
@since NEXT_RELEASE *)
let to_out_channel_top = to_out_channel ~top:true
+(** Produce a streaming writer from this HTML element.
+ @param top if true, add a DOCTYPE. See {!to_out_channel}.
+ @since NEXT_RELEASE *)
+let to_writer ?top (self : elt) : IO.Writer.t =
+ let write oc = to_out_channel ?top self oc in
+ IO.Writer.make ~write ()
+
(** Convert a HTML element to a stream. This might just convert
it to a string first, do not assume it to be more efficient. *)
let to_stream (self : elt) : Tiny_httpd_stream.t =
diff --git a/src/gen/gentags.ml b/src/gen/gentags.ml
index bdff004d..d956f14d 100644
--- a/src/gen/gentags.ml
+++ b/src/gen/gentags.ml
@@ -295,6 +295,7 @@ module Out : sig
type t
val create_of_buffer : Buffer.t -> t
val create_of_out: Tiny_httpd_io.Out_channel.t -> t
+ val flush : t -> unit
val add_char : t -> char -> unit
val add_string : t -> string -> unit
val add_format_nl : t -> unit
@@ -307,9 +308,10 @@ end = struct
}
let create_of_out out = {out; fmt_nl=true}
let create_of_buffer buf : t = create_of_out (IO.Out_channel.of_buffer buf)
+ let[@inline] flush self : unit = IO.Out_channel.flush self.out
let[@inline] add_char self c = IO.Out_channel.output_char self.out c
let[@inline] add_string self s = IO.Out_channel.output_string self.out s
- let add_format_nl self = if self.fmt_nl then add_char self '\n'
+ let[@inline] add_format_nl self = if self.fmt_nl then add_char self '\n'
let with_no_format_nl self f =
if self.fmt_nl then (
self.fmt_nl <- false;