Skip to content

Commit

Permalink
Add ZipStore storage backend.
Browse files Browse the repository at this point in the history
This commit adds a ZipStore storage backend as described in the
specification zarr-developers/zarr-specs#311 .
Note that the implementation loads the entire zip archive into memory so
care must be taken to ensure the zip archive is not too big to fit into
the machine's memory. To use a ZipStore impelementation that does not
load the archive into memory see `examples/zipstore.ml`.
  • Loading branch information
zoj613 committed Nov 6, 2024
1 parent 4ecee33 commit 8f3ad93
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 212 deletions.
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
(and (>= 4.14.0)))
(yojson (>= 1.6.0))
(stdint (>= 0.7.2))
(zipc (>= 0.2.0))
(checkseum (>= 0.4.0))
(odoc :with-doc)
(ounit2 :with-test)
Expand Down
6 changes: 0 additions & 6 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
(ocamlopt_flags (:standard -O3))
(libraries zarr-eio camlzip))

(executable
(name inmemory_zipstore)
(modules inmemory_zipstore)
(ocamlopt_flags (:standard -O3))
(libraries zarr-lwt zipc))

(executable
(name picos_fs_store)
(modules picos_fs_store)
Expand Down
203 changes: 0 additions & 203 deletions examples/inmemory_zipstore.ml

This file was deleted.

6 changes: 6 additions & 0 deletions zarr-eio/src/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module MemoryStore = struct
let create = Zarr.Memory.create
end

module ZipStore = struct
module Z = Zarr.Zip.Make(Deferred)
include Zarr.Storage.Make(Z)
let with_open = Z.with_open
end

module FilesystemStore = struct
module FS = struct
module Deferred = Deferred
Expand Down
3 changes: 3 additions & 0 deletions zarr-eio/src/storage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module MemoryStore : sig
(** [create ()] returns a new In-memory Zarr store type. *)
end

(** An Eio-aware Zip file storage backend for a Zarr v3 hierarchy. *)
module ZipStore : sig include Zarr.Zip.S with type 'a Deferred.t = 'a end

module FilesystemStore : sig
(** A local filesystem storage backend for a Zarr V3 hierarchy. *)

Expand Down
5 changes: 5 additions & 0 deletions zarr-eio/test/test_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ let _ =
(Zarr.Storage.Not_a_filesystem_store fn)
(fun () -> FilesystemStore.open_store ~env fn);

(* test with non-existant archive *)
let zpath = tmp_dir ^ ".zip" in
ZipStore.with_open `Read_write zpath (fun z -> test_storage (module ZipStore) z);
(* test just opening the now exisitant archive created by the previous test. *)
ZipStore.with_open `Read_only zpath (fun _ -> ZipStore.Deferred.return_unit);
test_storage (module MemoryStore) @@ MemoryStore.create ();
test_storage (module FilesystemStore) s)
])
6 changes: 6 additions & 0 deletions zarr-lwt/src/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module MemoryStore = struct
let create = Zarr.Memory.create
end

module ZipStore = struct
module Z = Zarr.Zip.Make(Deferred)
include Zarr.Storage.Make(Z)
let with_open = Z.with_open
end

module FilesystemStore = struct
module FS = struct
module Deferred = Deferred
Expand Down
3 changes: 3 additions & 0 deletions zarr-lwt/src/storage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module MemoryStore : sig
(** [create ()] returns a new In-memory Zarr store type. *)
end

(** An Lwt-aware Zip file storage backend for a Zarr v3 hierarchy. *)
module ZipStore : sig include Zarr.Zip.S with type 'a Deferred.t = 'a Lwt.t end

module FilesystemStore : sig
(** A local filesystem storage backend for a Zarr V3 hierarchy. *)

Expand Down
9 changes: 6 additions & 3 deletions zarr-lwt/test/test_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ let _ =
(Zarr.Storage.Not_a_filesystem_store fn)
(fun () -> FilesystemStore.open_store fn);

Lwt_main.run @@
Lwt.join
[test_storage (module MemoryStore) @@ MemoryStore.create ()
let zpath = tmp_dir ^ ".zip" in
Lwt_main.run @@ Lwt.join
[ZipStore.with_open `Read_write zpath (fun z -> test_storage (module ZipStore) z)
(* test just opening the now exisitant archive created by the previous test. *)
;ZipStore.with_open `Read_only zpath (fun _ -> ZipStore.Deferred.return_unit)
;test_storage (module MemoryStore) @@ MemoryStore.create ()
;test_storage (module FilesystemStore) s])
])
6 changes: 6 additions & 0 deletions zarr-sync/src/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module MemoryStore = struct
let create = Zarr.Memory.create
end

module ZipStore = struct
module Z = Zarr.Zip.Make(Deferred)
include Zarr.Storage.Make(Z)
let with_open = Z.with_open
end

module FilesystemStore = struct
module F = struct
module Deferred = Deferred
Expand Down
3 changes: 3 additions & 0 deletions zarr-sync/src/storage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module MemoryStore : sig
(** [create ()] returns a new In-memory Zarr store type. *)
end

(** A blocking I/O Zip file storage backend for a Zarr v3 hierarchy. *)
module ZipStore : sig include Zarr.Zip.S with type 'a Deferred.t = 'a end

module FilesystemStore : sig
(** A local filesystem storage backend for a Zarr V3 hierarchy. *)

Expand Down
5 changes: 5 additions & 0 deletions zarr-sync/test/test_sync.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ let _ =
(Zarr.Storage.Not_a_filesystem_store fn)
(fun () -> FilesystemStore.open_store fn);

(* test with non-existant archive *)
let zpath = tmp_dir ^ ".zip" in
ZipStore.with_open `Read_write zpath (fun z -> test_storage (module ZipStore) z);
(* test just opening the now exisitant archive created by the previous test. *)
ZipStore.with_open `Read_only zpath (fun _ -> ZipStore.Deferred.return_unit);
test_storage (module MemoryStore) @@ MemoryStore.create ();
test_storage (module FilesystemStore) s)
])
1 change: 1 addition & 0 deletions zarr.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ depends: [
"ocaml" {>= "4.14.0"}
"yojson" {>= "1.6.0"}
"stdint" {>= "0.7.2"}
"zipc" {>= "0.2.0"}
"checkseum" {>= "0.4.0"}
"odoc" {with-doc}
"ounit2" {with-test}
Expand Down
1 change: 1 addition & 0 deletions zarr/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
yojson
bytesrw.zstd
bytesrw.zlib
zipc
stdint
checkseum)
(ocamlopt_flags
Expand Down
Loading

0 comments on commit 8f3ad93

Please sign in to comment.