let output_lines prefix oc buffer =
let u = Buffer.contents buffer in
let m = String.length u in
let output_line i j =
output_string oc prefix;
output oc u i (j - i);
output_char oc '\n'
in
let rec loop i =
if i = m then
()
else
begin
try
let j = String.index_from u i '\n' in
output_line i j;
loop (j + 1)
with
| Not_found ->
output_line i m
end
in
loop 0