This commit is contained in:
Simon Cruanes 2022-03-01 16:59:23 -05:00
parent 0078d91672
commit 10ade90dfd
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 39 additions and 0 deletions

View file

@ -277,3 +277,26 @@ let add_vfs ~config ~vfs ~prefix server : unit =
let add_dir_path ~config ~dir ~prefix server : unit = let add_dir_path ~config ~dir ~prefix server : unit =
add_vfs_ ~on_fs:true ~top:dir ~config ~prefix ~vfs:(vfs_of_dir dir) server add_vfs_ ~on_fs:true ~top:dir ~config ~prefix ~vfs:(vfs_of_dir dir) server
module Embedded_fs = struct
module Str_tbl = Hashtbl.Make(struct
include String
let hash = Hashtbl.hash
end)
type t = {
entries: entry Str_tbl.t
} [@@unboxed]
and entry =
| File of {
content: string;
}
| Dir of t
(* TODO: the rest *)
(* TODO: use util.split_on_slash *)
end

View file

@ -130,3 +130,19 @@ val add_vfs :
@since NEXT_RELEASE @since NEXT_RELEASE
*) *)
(** An embedded file system, as a list of files with (relative) paths.
This is useful in combination with the "tiny-httpd-mkfs" tool,
which embeds the files it's given into a OCaml module.
@since NEXT_RELEASE
*)
module Embedded_fs : sig
type t
(** The pseudo-filesystem *)
val create : unit -> t
val add_file : t -> path:string -> string -> unit
val to_vfs : t -> (module VFS)
end