11module type S = sig
22 exception Not_implemented
33 exception Request_failed of int * string
4- include Storage. STORE
4+ include Storage. S
55
66 type auth = {user : string ; pwd : string }
77
@@ -11,8 +11,8 @@ module type S = sig
1111 ?tries : int ->
1212 ?timeout : int ->
1313 string ->
14- (t -> 'a Deferred .t ) ->
15- 'a Deferred .t
14+ (t -> 'a io ) ->
15+ 'a io
1616 (* * [with_open url f] connects to the Zarr store described by the url [url]
1717 and applies function [f] to the store's open handle.
1818
@@ -37,20 +37,17 @@ module type C = sig
3737 include Ezcurl_core. S
3838end
3939
40- module Make
41- (Deferred : Types.Deferred )
42- (C : C with type 'a io = 'a Deferred.t ) : S with module Deferred = Deferred = struct
40+ module Make (IO : Types.IO ) (C : C with type 'a io = 'a IO.t ) : S with type 'a io := 'a IO. t = struct
4341 exception Not_implemented
4442 exception Request_failed of int * string
45- open Deferred .Syntax
43+ open IO .Syntax
4644
4745 let raise_error (code , s ) = raise (Request_failed (Curl. int_of_curlCode code, s))
4846 let fold_result = Result. fold ~error: raise_error ~ok: Fun. id
4947
50- module IO = struct
51- module Deferred = Deferred
52-
48+ module Store = struct
5349 type t = {tries : int ; client : C .t ; base_url : string ; config : Ezcurl_core.Config .t }
50+ type 'a io = 'a IO .t
5451
5552 let get t key =
5653 let tries = t.tries and client = t.client and config = t.config in
@@ -60,29 +57,29 @@ module Make
6057 | {code; body; _} when code = 200 -> body
6158 | {code; body; _} -> raise (Request_failed (code, body))
6259
63- let size t key = try Deferred . map String. length (get t key) with
64- | Request_failed (404 , _ ) -> Deferred . return 0
60+ let size t key = try IO . map String. length (get t key) with
61+ | Request_failed (404 , _ ) -> IO . return 0
6562 (* let size t key =
6663 let tries = t.tries and client = t.client and config = t.config in
6764 let url = t.base_url ^ key in
6865 let type' = if String.ends_with ~suffix:".json" key then "json" else "octet-stream" in
6966 let headers = [("Content-Type", "application/" ^ type')] in
7067 let* res = C.http ~headers ~tries ~client ~config ~url ~meth:HEAD () in
7168 match res with
72- | Error _ -> Deferred .return 0
73- | Ok {code; _} when code = 404 -> Deferred .return 0
69+ | Error _ -> IO .return 0
70+ | Ok {code; _} when code = 404 -> IO .return 0
7471 | Ok {headers; code; _} when code = 200 ->
7572 begin match List.assoc_opt "content-length" headers with
76- | Some "0" -> Deferred .return 0
77- | Some l -> Deferred .return @@ int_of_string l
73+ | Some "0" -> IO .return 0
74+ | Some l -> IO .return @@ int_of_string l
7875 | None ->
7976 begin try print_endline "empty content-length header";
80- Deferred .map String.length (get t key) with
81- | Request_failed (404, _) -> Deferred .return 0 end
77+ IO .map String.length (get t key) with
78+ | Request_failed (404, _) -> IO .return 0 end
8279 end
8380 | Ok {code; body; _} -> raise (Request_failed (code, body)) *)
8481
85- let is_member t key = Deferred . map (fun s -> if s > 0 then true else false ) (size t key)
82+ let is_member t key = IO . map (fun s -> if s > 0 then true else false ) (size t key)
8683
8784 let get_partial_values t key ranges =
8885 let tries = t.tries and client = t.client and config = t.config and url = t.base_url ^ key in
@@ -91,9 +88,9 @@ module Make
9188 let read_range acc (ofs , len ) =
9289 let none = Printf. sprintf " %d-" ofs in
9390 let range = Option. fold ~none ~some: (end_index ofs) len in
94- Deferred . map (fun r -> (fold_result r).body :: acc) (fetch range)
91+ IO . map (fun r -> (fold_result r).body :: acc) (fetch range)
9592 in
96- Deferred . fold_left read_range [] (List. rev ranges)
93+ IO . fold_left read_range [] (List. rev ranges)
9794
9895 let set t key data =
9996 let tries = t.tries and client = t.client and config = t.config
@@ -110,7 +107,7 @@ module Make
110107 let set_partial_values t key ?(append =false ) rsv =
111108 let * size = size t key in
112109 let * ov = match size with
113- | 0 -> Deferred . return String. empty
110+ | 0 -> IO . return String. empty
114111 | _ -> get t key
115112 in
116113 let f = if append || ov = String. empty then
@@ -149,9 +146,9 @@ module Make
149146 |> Ezcurl_core.Config. username basic_auth.user
150147 |> Ezcurl_core.Config. password basic_auth.pwd
151148 in
152- f IO . {tries; client; config; base_url = url ^ " /" }
149+ f Store . {tries; client; config; base_url = url ^ " /" }
153150 in
154151 C. with_client ~set_opts perform
155152
156- include Storage. Make (IO )
153+ include Storage. Make (IO )( Store )
157154end
0 commit comments