add iterator functions to CCIO

This commit is contained in:
Simon Cruanes 2021-08-19 10:21:12 -04:00
parent 6b99433716
commit 76b108203a
No known key found for this signature in database
GPG key ID: 4AC01D0849AA62B6
2 changed files with 28 additions and 2 deletions

View file

@ -101,6 +101,10 @@ let read_chunks_gen ?(size=1024) ic =
in
next
let read_chunks_iter ?size ic =
let g = read_chunks_gen ?size ic in
fun yield -> gen_iter yield g
let read_chunks_seq ?size ic =
seq_of_gen_ (read_chunks_gen ?size ic)
@ -118,6 +122,10 @@ let read_lines_gen ic =
let read_lines_seq ic =
seq_of_gen_ (read_lines_gen ic)
let read_lines_iter ic =
let g = read_lines_gen ic in
fun yield -> gen_iter yield g
let read_lines_l ic =
let l = ref [] in
try
@ -218,6 +226,8 @@ let rec write_lines oc g = match g () with
let write_lines_seq oc seq =
Seq.iter (write_line oc) seq
let write_lines_iter oc i = i (write_line oc)
let write_lines_l oc l =
List.iter (write_line oc) l

View file

@ -68,16 +68,20 @@ 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_gen : ?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 at most [size].
{b NOTE} the generator must be used within the lifetime of the channel,
see warning at the top of the file. *)
val read_chunks_seq : ?size:int -> in_channel -> string Seq.t
(** Read the channel's content into chunks of size [size].
(** Read the channel's content into chunks of size at most [size].
{b NOTE} the generator must be used within the lifetime of the channel,
see warning at the top of the file.
@since 3.5 *)
val read_chunks_iter : ?size:int -> in_channel -> string iter
(** Read the channel's content into chunks of size at most [size]
@since NEXT_RELEASE *)
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. *)
@ -93,6 +97,10 @@ val read_lines_seq : in_channel -> string Seq.t
see warning at the top of the file.
@since 3.5 *)
val read_lines_iter : in_channel -> string iter
(** Read all lines.
@since NEXT_RELEASE *)
val read_lines_l : in_channel -> string list
(** Read all lines into a list. *)
@ -136,6 +144,10 @@ val write_seq : ?sep:string -> out_channel -> string Seq.t -> unit
val write_lines : out_channel -> string gen -> unit
(** Write every string on the output, followed by "\n". *)
val write_lines_iter : out_channel -> string iter -> unit
(** Write every string on the output, followed by "\n".
@since NEXT_RELEASE *)
val write_lines_seq : out_channel -> string Seq.t -> unit
(** Write every string on the output, followed by "\n".
@since 3.5 *)
@ -260,6 +272,10 @@ module File : sig
take some time on large directories).
@since 1.1 *)
val walk_seq : t -> walk_item Seq.t
(** Like {!walk} but returns a Seq
@since NEXT_RELEASE *)
val show_walk_item : walk_item -> string
val with_temp :