Skip to content

Commit 6b0cc2c

Browse files
committed
more updates for IO
1 parent 5ec3553 commit 6b0cc2c

File tree

8 files changed

+36
-40
lines changed

8 files changed

+36
-40
lines changed

zarr-eio/src/storage.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ module HttpStore = struct
146146
raise (Zarr.Storage.Key_not_found key)
147147
| e -> raise_status_error e
148148

149-
module IO = struct
150-
module Deferred = Deferred
151-
149+
module S = struct
152150
type t = {base_url : Uri.t; client : Client.t}
151+
type 'a io = 'a IO.t
153152

154153
let get t key =
155154
Eio.Switch.run @@ fun sw ->
@@ -220,7 +219,7 @@ module HttpStore = struct
220219

221220
let with_open ?https ~net uri f =
222221
let client = Client.make ~https net in
223-
f IO.{client; base_url = uri}
222+
f S.{client; base_url = uri}
224223

225-
include Zarr.Storage.Make(IO)
224+
include Zarr.Storage.Make(IO)(S)
226225
end

zarr-eio/src/storage.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424
module HttpStore : sig
2525
exception Not_implemented
2626
exception Request_failed of int * string
27-
include Zarr.Storage.STORE with module Deferred = Deferred
27+
include Zarr.Storage.S with type 'a io := 'a
2828
val with_open :
2929
?https:(Uri.t -> [ `Generic ] Eio.Net.stream_socket_ty Eio.Std.r -> _ Eio.Flow.two_way) ->
3030
net:_ Eio.Net.t ->

zarr-eio/test/test_eio.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let test_storage
9999

100100
module type SYNC_PARTIAL_STORE = sig
101101
exception Not_implemented
102-
include Zarr.Storage.STORE with type 'a Deferred.t = 'a
102+
include Zarr.Storage.S with type 'a io := 'a
103103
end
104104

105105
let test_readable_writable_only

zarr-lwt/src/storage.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module MemoryStore : Zarr.Memory.S with type 'a io := 'a Lwt.t
77
module ZipStore : Zarr.Zip.S with type 'a io := 'a Lwt.t
88

99
(** An Lwt-aware Http storage backend for a Zarr v3 hierarchy. *)
10-
module HttpStore : Zarr.Http.S with module Deferred = Deferred
10+
module HttpStore : Zarr.Http.S with type 'a io := 'a Lwt.t
1111

1212
(** An Lwt-aware local filesystem storage backend for a Zarr V3 hierarchy. *)
1313
module FilesystemStore : sig

zarr-lwt/test/test_lwt.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ let test_storage
115115

116116
module type SYNC_PARTIAL_STORE = sig
117117
exception Not_implemented
118-
include Zarr.Storage.STORE with type 'a Deferred.t = 'a Lwt.t
118+
include Zarr.Storage.S with type 'a io := 'a Lwt.t
119119
end
120120

121121
let test_readable_writable_only
122122
(type a) (module M : SYNC_PARTIAL_STORE with type t = a) (store : a) =
123123
let open M in
124-
let open Deferred.Syntax in
124+
let open IO.Syntax in
125125
let assert_not_implemented f =
126126
Lwt.catch
127-
(fun () -> let* _ = f () in Deferred.return_unit)
127+
(fun () -> let* _ = f () in IO.return_unit)
128128
(function
129-
| Not_implemented -> Deferred.return_unit
129+
| Not_implemented -> IO.return_unit
130130
| _ -> failwith "Supposed to raise Not_implemented")
131131
in
132132
let gnode = Node.Group.root in
@@ -171,7 +171,7 @@ let test_readable_writable_only
171171
let* () = assert_not_implemented (fun () -> hierarchy store) in
172172
let* () = assert_not_implemented (fun () -> Group.delete store gnode) in
173173
let* () = assert_not_implemented (fun () -> clear store) in
174-
Deferred.return_unit
174+
IO.return_unit
175175

176176
module Dir_http_server = struct
177177
module S = Tiny_httpd
@@ -243,7 +243,7 @@ module Dir_http_server = struct
243243
let perform () =
244244
let _ = Thread.create S.run_exn t in
245245
Lwt.dont_wait after_init raise;
246-
Deferred.return_unit
246+
IO.return_unit
247247
in
248248
Fun.protect ~finally:(fun () -> S.stop t) perform
249249
end

zarr-sync/src/storage.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module MemoryStore : Zarr.Memory.S with type 'a io := 'a
77
module ZipStore : Zarr.Zip.S with type 'a io := 'a
88

99
(** A blocking I/O Http storage backend for a Zarr v3 hierarchy. *)
10-
module HttpStore : Zarr.Http.S with module Deferred = Deferred
10+
module HttpStore : Zarr.Http.S with type 'a io := 'a
1111

1212
(** A blocking I/O local filesystem storage backend for a Zarr v3 hierarchy. *)
1313
module FilesystemStore : sig

zarr-sync/test/test_sync.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ let test_storage
161161

162162
module type SYNC_PARTIAL_STORE = sig
163163
exception Not_implemented
164-
include Zarr.Storage.STORE with type 'a Deferred.t = 'a
164+
include Zarr.Storage.S with type 'a io := 'a
165165
end
166166

167167
let test_readable_writable_only

zarr/src/storage/http.ml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module 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
3838
end
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)
157154
end

0 commit comments

Comments
 (0)