Skip to content

Commit

Permalink
update some more
Browse files Browse the repository at this point in the history
  • Loading branch information
zoj613 committed Dec 25, 2024
1 parent 2a6ced3 commit de070e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions zarr-eio/src/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ module HttpStore = struct
let rename _ = raise Not_implemented
end

let with_open ~net uri f =
let client = Client.make ~https:None net in
let with_open ?https ~net uri f =
let client = Client.make ~https net in
f IO.{client; base_url = uri}

include Zarr.Storage.Make(IO)
Expand Down
1 change: 1 addition & 0 deletions zarr-eio/src/storage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module HttpStore : sig
exception Request_failed of int * string
include Zarr.Storage.STORE with module Deferred = Deferred
val with_open :
?https:(Uri.t -> [ `Generic ] Eio.Net.stream_socket_ty Eio.Std.r -> _ Eio.Flow.two_way) ->
net:_ Eio.Net.t ->
Uri.t ->
(t -> 'a) ->
Expand Down
23 changes: 7 additions & 16 deletions zarr/src/storage/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ module Make

module IO = struct
module Deferred = Deferred
open Deferred.Infix

type t =
{tries : int
;client : C.t
;base_url : string
;config : Ezcurl_core.Config.t}
type t = {tries : int; client : C.t; base_url : string; config : Ezcurl_core.Config.t}

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

let size t key = try get t key >>| String.length with
let size t key = try Deferred.map String.length (get t key) with
| Request_failed (404, _) -> Deferred.return 0
(*let size t key =
let tries = t.tries and client = t.client and config = t.config in
Expand All @@ -82,25 +77,21 @@ module Make
| Some l -> Deferred.return @@ int_of_string l
| None ->
begin try print_endline "empty content-length header";
get t key >>| String.length with
Deferred.map String.length (get t key) with
| Request_failed (404, _) -> Deferred.return 0 end
end
| Ok {code; body; _} -> raise (Request_failed (code, body)) *)

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

let get_partial_values t key ranges =
let tries = t.tries and client = t.client and config = t.config and url = t.base_url ^ key in
let fetch range = C.get ~range ~tries ~client ~config ~url () in
let end_index ofs l = Printf.sprintf "%d-%d" ofs (ofs + l - 1) in
let fetch range = C.get ~range ~tries ~client ~config ~url ()
and end_index ofs l = Printf.sprintf "%d-%d" ofs (ofs + l - 1) in
let read_range acc (ofs, len) =
let none = Printf.sprintf "%d-" ofs in
let range = Option.fold ~none ~some:(end_index ofs) len in
let+ res = fetch range in
let response = fold_result res in
response.body :: acc
Deferred.map (fun r -> (fold_result r).body :: acc) (fetch range)
in
Deferred.fold_left read_range [] (List.rev ranges)

Expand Down

0 comments on commit de070e8

Please sign in to comment.