let rec output oz buf pos len =
if pos < 0 || len < 0 || pos + len > String.length buf then invalid_arg "Biocaml_bgzf.output";
(* If output buffer is full, flush it *)
if oz.out_pos = String.length oz.out_ubuffer then push_block oz ;
let available = String.length oz.out_ubuffer - oz.out_pos in
let ncopy = min len available in
String.blit buf pos oz.out_ubuffer oz.out_pos ncopy ;
oz.out_pos <- oz.out_pos + ncopy ;
let remaining = len - ncopy in
if remaining > 0 then output oz buf (pos + ncopy) remaining