(* Return the contents of an in_channel as a stream of strings. If the limit argument is greater than zero, it represents the number of reads allowed from the channel. These reads are generally 4096 characters, but this is not guaranteed. *) let to_stringstream ?(limit=0) chan = let len = Unixutils.pipe_buf () in let buf = String.create len in let read chan buf len = match input chan buf 0 len with 0 -> None | n when n = len -> Some (String.copy buf) | n -> Some (String.sub buf 0 n) in match limit with 0 -> Stream.from (fun count -> read chan buf len) | _ -> Stream.from (fun count -> if count > limit then None else read chan buf len) let to_linestream chan = Linestream.of_stringstream (to_stringstream chan) let to_string chan = let strm = to_stringstream chan in String.concat "" (Stream2.to_list strm)