Skip to content
Newer
Older
100644 44 lines (31 sloc) 987 Bytes
a4e794d @joearms starting
authored Mar 1, 2012
1 %% Copyright (c) 2006-2009 Joe Armstrong
2 %% See MIT-LICENSE for licensing information.
3
4 -module(elib1_blob_store).
5
6 %% The guid store is a two level store
7 %%
8 %% M:init(File)
9 %% M:store(Key, Blob)
10 %% M:fetch(Key) -> Blob raises eNoKey
11 %% M:keys() -> [Key]
12
13 -export([open/1, close/0, fetch/1, store/2, keys/0]).
14
15 open(File) ->
16 %% io:format("dets opened:~p~n", [File]),
17 case dets:open_file(?MODULE, [{file, File}]) of
18 {ok, ?MODULE} ->
19 true;
20 {error,_Reason} ->
21 io:format("cannot open dets table~n"),
22 exit(eDetsOpen)
23 end.
24
25 close() -> dets:close(?MODULE).
26
27 store(Key, Blob) when is_binary(Blob) ->
28 %% io:format("storing blob key=~p size=~p~n",[Key,size(Blob)]),
29 ok = dets:insert(?MODULE, [{Key,Blob}]).
30
31 fetch(Key) ->
32 case dets:lookup(?MODULE, Key) of
33 [] -> error;
34 [{_,Blob}] -> {ok, Blob}
35 end.
36
37 keys() ->
38 %% I guess there is a better way of doing this ...
39 dets:foldl(fun({K,_},A) -> [K|A] end,[],?MODULE).
40
41
42
43
Something went wrong with that request. Please try again.