feat(CCIO): add _gen suffixes to some functions

deprecate the previous versions
see #261
This commit is contained in:
Simon Cruanes 2019-11-11 19:55:43 -06:00
parent edcd97a7ed
commit 27fb393698
2 changed files with 22 additions and 6 deletions

View file

@ -65,7 +65,7 @@ let with_in ?(mode=0o644) ?(flags=[Open_text]) filename f =
let ic = open_in_gen (Open_rdonly::flags) mode filename in
finally_ f ic ~h:close_in
let read_chunks ?(size=1024) ic =
let read_chunks_gen ?(size=1024) ic =
let buf = Bytes.create size in
let next() =
let n = input ic buf 0 size in
@ -75,17 +75,21 @@ let read_chunks ?(size=1024) ic =
in
next
let read_chunks = read_chunks_gen
let read_line ic =
try Some (input_line ic)
with End_of_file -> None
let read_lines ic =
let read_lines_gen ic =
let stop = ref false in
fun () ->
if !stop then None
else try Some (input_line ic)
with End_of_file -> (stop:=true; None)
let read_lines = read_lines_gen
let read_lines_l ic =
let l = ref [] in
try

View file

@ -20,7 +20,7 @@
# CCIO.(
with_in "/tmp/input"
(fun ic ->
let chunks = read_chunks ic in
let chunks = read_chunks_gen ic in
with_out ~flags:[Open_binary; Open_creat] ~mode:0o644 "/tmp/output"
(fun oc ->
write_gen oc chunks
@ -37,7 +37,7 @@
# CCIO.(
let chunks =
with_in "/tmp/input"
(fun ic ->read_chunks ic)
(fun ic -> read_chunks_gen ic)
in
with_out ~flags:[Open_binary;Open_creat] ~mode:0o644 "/tmp/output"
(fun oc ->
@ -67,14 +67,26 @@ val with_in : ?mode:int -> ?flags:open_flag list ->
@param flags opening flags (default [[Open_text]]). [Open_rdonly] is used in any cases. *)
val read_chunks : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size]. *)
(** Read the channel's content into chunks of size [size].
@deprecated use {!read_chunks_gen} instead. *)
val read_chunks_gen : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size].
{b NOTE} the generator must be used within the lifetime of the channel,
see warning at the top of the file. *)
val read_line : in_channel -> string option
(** Read a line from the channel. Returns [None] if the input is terminated.
The "\n" is removed from the line. *)
val read_lines : in_channel -> string gen
(** Read all lines. The generator should be traversed only once. *)
(** Read all lines. The generator should be traversed only once.
@deprecated use {!read_lines_gen} instead. *)
val read_lines_gen : in_channel -> string gen
(** Read all lines. The generator should be traversed only once.
{b NOTE} the generator must be used within the lifetime of the channel,
see warning at the top of the file. *)
val read_lines_l : in_channel -> string list
(** Read all lines into a list. *)