File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,13 @@ module Lazy = Lazy
12
12
module Pool = Pool
13
13
module Exn = Exn
14
14
module Resource = Resource
15
- module Flow = Flow
16
15
module Buf_read = Buf_read
16
+ module Flow = struct
17
+ include Flow
18
+
19
+ let read_all flow =
20
+ Buf_read. (parse_exn take_all) flow ~max_size: max_int
21
+ end
17
22
module Buf_write = Buf_write
18
23
module Net = Net
19
24
module Process = Process
Original file line number Diff line number Diff line change @@ -60,7 +60,12 @@ module Std = Std
60
60
module Resource = Resource
61
61
62
62
(* * Byte streams. *)
63
- module Flow = Flow
63
+ module Flow : sig
64
+ include module type of Flow
65
+
66
+ val read_all : _ source -> string
67
+ (* * [read_all src] is a convenience wrapper to read an entire flow efficiently. *)
68
+ end
64
69
65
70
(* * Buffered input and parsing *)
66
71
module Buf_read = Buf_read
Original file line number Diff line number Diff line change @@ -241,7 +241,8 @@ Exception: End_of_file.
241
241
242
242
``` ocaml
243
243
# let bflow = R.of_flow mock_flow ~max_size:100 |> R.as_flow;;
244
- val bflow : Eio.Flow.source_ty Eio.Std.r = Eio__.Resource.T (<poly>, <abstr>)
244
+ val bflow : Eio__Flow.source_ty Eio.Std.r =
245
+ Eio__.Resource.T (<poly>, <abstr>)
245
246
# next := ["foo"; "bar"]; read bflow 2;;
246
247
+mock_flow returning 3 bytes
247
248
+Read "fo"
Original file line number Diff line number Diff line change @@ -108,6 +108,22 @@ Copying from src using `Read_source_buffer`:
108
108
- : unit = ()
109
109
```
110
110
111
+ ## read_all
112
+
113
+ ``` ocaml
114
+ # run @@ fun () ->
115
+ let each = String.init 256 Char.chr in
116
+ let data = List.init 40 (fun _ -> Cstruct.of_string each) in
117
+ let got = Eio.Flow.read_all (mock_source data) in
118
+ traceln "Input length: %d\nOutput length: %d\nEqual: %b"
119
+ (Cstruct.lenv data) (String.length got) (String.equal got (Cstruct.copyv data));
120
+ ;;
121
+ +Input length: 10240
122
+ +Output length: 10240
123
+ +Equal: true
124
+ - : unit = ()
125
+ ```
126
+
111
127
## write
112
128
113
129
``` ocaml
You can’t perform that action at this time.
0 commit comments