Compare commits

..

3 Commits

Author SHA1 Message Date
Thomas Leonard
ee51b04408
Merge pull request #596 from SGrondin/add-flow-load
Add Flow.read_all
2023-10-11 10:26:37 +01:00
Thomas Leonard
c6067a9059 Improve odoc for read_all 2023-10-11 09:54:23 +01:00
Simon Grondin
8da6a7d7f1 Add Flow.read_all 2023-10-11 09:54:19 +01:00
4 changed files with 34 additions and 3 deletions

View File

@ -12,8 +12,13 @@ module Lazy = Lazy
module Pool = Pool module Pool = Pool
module Exn = Exn module Exn = Exn
module Resource = Resource module Resource = Resource
module Flow = Flow
module Buf_read = Buf_read module Buf_read = Buf_read
module Flow = struct
include Flow
let read_all flow =
Buf_read.(parse_exn take_all) flow ~max_size:max_int
end
module Buf_write = Buf_write module Buf_write = Buf_write
module Net = Net module Net = Net
module Process = Process module Process = Process

View File

@ -60,7 +60,16 @@ module Std = Std
module Resource = Resource module Resource = Resource
(** Byte streams. *) (** Byte streams. *)
module Flow = Flow module Flow : sig
include module type of Flow (** @inline *)
(** {2 Convenience wrappers} *)
val read_all : _ source -> string
(** [read_all src] is a convenience wrapper to read an entire flow.
It is the same as [Buf_read.(parse_exn take_all) src ~max_size:max_int] *)
end
(** Buffered input and parsing *) (** Buffered input and parsing *)
module Buf_read = Buf_read module Buf_read = Buf_read

View File

@ -241,7 +241,8 @@ Exception: End_of_file.
```ocaml ```ocaml
# let bflow = R.of_flow mock_flow ~max_size:100 |> R.as_flow;; # let bflow = R.of_flow mock_flow ~max_size:100 |> R.as_flow;;
val bflow : Eio.Flow.source_ty Eio.Std.r = Eio__.Resource.T (<poly>, <abstr>) val bflow : Eio__Flow.source_ty Eio.Std.r =
Eio__.Resource.T (<poly>, <abstr>)
# next := ["foo"; "bar"]; read bflow 2;; # next := ["foo"; "bar"]; read bflow 2;;
+mock_flow returning 3 bytes +mock_flow returning 3 bytes
+Read "fo" +Read "fo"

View File

@ -108,6 +108,22 @@ Copying from src using `Read_source_buffer`:
- : unit = () - : unit = ()
``` ```
## read_all
```ocaml
# run @@ fun () ->
let each = String.init 256 Char.chr in
let data = List.init 40 (fun _ -> Cstruct.of_string each) in
let got = Eio.Flow.read_all (mock_source data) in
traceln "Input length: %d\nOutput length: %d\nEqual: %b"
(Cstruct.lenv data) (String.length got) (String.equal got (Cstruct.copyv data));
;;
+Input length: 10240
+Output length: 10240
+Equal: true
- : unit = ()
```
## write ## write
```ocaml ```ocaml