Skip to content

Commit de070e8

Browse files
committed
update some more
1 parent 2a6ced3 commit de070e8

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

zarr-eio/src/storage.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ module HttpStore = struct
218218
let rename _ = raise Not_implemented
219219
end
220220

221-
let with_open ~net uri f =
222-
let client = Client.make ~https:None net in
221+
let with_open ?https ~net uri f =
222+
let client = Client.make ~https net in
223223
f IO.{client; base_url = uri}
224224

225225
include Zarr.Storage.Make(IO)

zarr-eio/src/storage.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module HttpStore : sig
2626
exception Request_failed of int * string
2727
include Zarr.Storage.STORE with module Deferred = Deferred
2828
val with_open :
29+
?https:(Uri.t -> [ `Generic ] Eio.Net.stream_socket_ty Eio.Std.r -> _ Eio.Flow.two_way) ->
2930
net:_ Eio.Net.t ->
3031
Uri.t ->
3132
(t -> 'a) ->

zarr/src/storage/http.ml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ module Make
4949

5050
module IO = struct
5151
module Deferred = Deferred
52-
open Deferred.Infix
5352

54-
type t =
55-
{tries : int
56-
;client : C.t
57-
;base_url : string
58-
;config : Ezcurl_core.Config.t}
53+
type t = {tries : int; client : C.t; base_url : string; config : Ezcurl_core.Config.t}
5954

6055
let get t key =
6156
let tries = t.tries and client = t.client and config = t.config in
@@ -65,7 +60,7 @@ module Make
6560
| {code; body; _} when code = 200 -> body
6661
| {code; body; _} -> raise (Request_failed (code, body))
6762

68-
let size t key = try get t key >>| String.length with
63+
let size t key = try Deferred.map String.length (get t key) with
6964
| Request_failed (404, _) -> Deferred.return 0
7065
(*let size t key =
7166
let tries = t.tries and client = t.client and config = t.config in
@@ -82,25 +77,21 @@ module Make
8277
| Some l -> Deferred.return @@ int_of_string l
8378
| None ->
8479
begin try print_endline "empty content-length header";
85-
get t key >>| String.length with
80+
Deferred.map String.length (get t key) with
8681
| Request_failed (404, _) -> Deferred.return 0 end
8782
end
8883
| Ok {code; body; _} -> raise (Request_failed (code, body)) *)
8984

90-
let is_member t key =
91-
let+ s = size t key in
92-
if s > 0 then true else false
85+
let is_member t key = Deferred.map (fun s -> if s > 0 then true else false) (size t key)
9386

9487
let get_partial_values t key ranges =
9588
let tries = t.tries and client = t.client and config = t.config and url = t.base_url ^ key in
96-
let fetch range = C.get ~range ~tries ~client ~config ~url () in
97-
let end_index ofs l = Printf.sprintf "%d-%d" ofs (ofs + l - 1) in
89+
let fetch range = C.get ~range ~tries ~client ~config ~url ()
90+
and end_index ofs l = Printf.sprintf "%d-%d" ofs (ofs + l - 1) in
9891
let read_range acc (ofs, len) =
9992
let none = Printf.sprintf "%d-" ofs in
10093
let range = Option.fold ~none ~some:(end_index ofs) len in
101-
let+ res = fetch range in
102-
let response = fold_result res in
103-
response.body :: acc
94+
Deferred.map (fun r -> (fold_result r).body :: acc) (fetch range)
10495
in
10596
Deferred.fold_left read_range [] (List.rev ranges)
10697

0 commit comments

Comments
 (0)