Page
Library
Module
Module type
Parameter
Class
Class type
Source
Multipart_form_eioSourceval stream :
sw:Eio.Switch.t ->
?bounds:int ->
?buffer_size:int ->
identify:(Multipart_form.Header.t -> 'id) ->
_ Eio.Flow.source ->
Multipart_form.Content_type.t ->
('id Multipart_form.t, [> `Msg of string ]) result Eio.Promise.or_exn
* ('id * Multipart_form.Header.t * string option Eio.Stream.t) option
Eio.Stream.tstream ~identify flow content_type returns:
th about the parserEach part contains an id, header, and content stream where None signals end of part content.
Example saving parts to files:
val save_part : filename:string -> Header.t -> string option Eio.Stream.t -> unit
Eio.Switch.run @@ fun sw ->
let identify _ : string = random_unique_filename () in
let th, parts = stream ~sw ~identify flow content_type in
let rec save_parts () =
match Eio.Stream.take parts with
| None -> () (* No more parts *)
| Some (filename, hdr, contents) ->
save_part ~filename hdr contents;
save_parts ()
in
Eio.Fiber.fork ~sw save_parts;
Eio.Promise.await_exn thParts are produced as the input is parsed. The promise resolves when parsing completes or fails.
These functions will store the entire multipart contents in memory, and therefore should not be used when handling possibly large data.
val of_flow_to_list :
_ Eio.Flow.source ->
Multipart_form.Content_type.t ->
(int Multipart_form.t * (int * string) list, [> `Msg of string ]) resultSimilar to Multipart_form.of_string_to_list, but consumes an Eio.Flow.source.
val of_flow_to_tree :
_ Eio.Flow.source ->
Multipart_form.Content_type.t ->
(string Multipart_form.t, [> `Msg of string ]) resultof_flow_to_tree flow content_type returns, if it succeeds, a value Multipart_form.t representing the multipart document, where the contents of the parts are stored as strings. It is equivalent to of_flow_to_list where references have been replaced with their associated contents.