fix
[camlunity.git] / storage.ml
blob18a299ce9852808fc9ecc4fdc11a6dd97cd8122e
2 open Prelude
4 type key = [ `I of int | `S of string ]
6 module type T = sig
8 type t
9 val create : string -> t
10 val close : t -> unit
11 val get : t -> key -> string option
12 val add : t -> key -> string -> unit
14 end
16 module Fs : T = struct
18 type t = string
19 let create path = (try Unix.mkdir path 0o777 with Unix.Unix_error (Unix.EEXIST,_,_) -> () | e -> raise e); path
20 let close _ = ()
21 let make = function
22 | `I n -> string_of_int n
23 | `S s -> Digest.to_hex (Digest.string s)
24 let get path name = try Std.input_file (Filename.concat path (make name)) >> some with _ -> None
25 let add path name value = Std.output_file (Filename.concat path (make name)) value
27 end