Subversion Repositories PlanixRsrch.SVN

Compare Revisions

Ignore whitespace Rev 56 → Rev 57

/branches/ddb/ddb/ddb.erl
1,20 → 1,29
-module (ddb).
%%%-------------------------------------------------------------------
%%% @author Tube <tube@xdevel.cauwersin.com>
%%% @copyright (C) 2019, Tube
%%% @doc
%%%
%%% @end
%%% Created : 8 Oct 2019 by Tube <tube@xdevel.cauwersin.com>
%%%-------------------------------------------------------------------
-module(ddb).
 
-export ([
start/0,
get_block/3
]).
get_block/3,
startx/0,
run/0
]).
 
big_o(0,L) ->
L;
big_o(N,L) ->
big_o(N-1, <<L/binary,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1>>).
 
big_o(N) ->
big_o(N,<<>>).
 
big_o(N) -> big_o(N,<<>>).
 
 
start() ->
{ok,File} = file:open("/tmp/ddb.dat",[read,write,binary]),
io:format("~p~n",[File]),
23,8 → 32,59
file:write(File,W),
file:close(File).
 
 
get_dir()->
"/tmp/".
 
 
get_block_filename(Folder,Id) ->
Folder++"/"++integer_to_list(Id).
 
get_block(Id,Start,End) ->
Filename = get_dir()++"ddb"++integer_to_list(Id).
Filename = get_dir()++"ddb"++integer_to_list(Id),
io:format("~p~n",[Filename]),
{Status,F} = file:open(Filename,[read,binary]),
case Status of
ok ->
file:pread(F,Start,End);
_ ->
{Status,F}
end.
 
-record ( data,
{
folder,
bats
}
).
 
run(WData) ->
receive
{Sender, store, Id, Data } when is_integer(Id) ->
save_block_to_disk(WData#data.folder,Id,Data),
Sender ! {self(), stored, Id};
 
Y ->
io:format("Received: ~p~n",[Y])
end,
run(WData).
 
 
save_block_to_disk(Folder,Id,Data) when is_binary(Data) ->
Filename = get_block_filename(Folder,Id),
{ok,File} = file:open(Filename,[read,write,binary]),
ok = file:write(File,Data),
ok = file:close(File);
save_block_to_disk(Folder,Id,Data) when is_list(Data) ->
save_block_to_disk(Folder,Id,list_to_binary(Data));
save_block_to_disk(Folder,Id,Data) ->
save_block_to_disk(Folder,Id,term_to_binary(Data)).
 
run() ->
WData = #data{
folder = "/tmp/ddb"
},
run(WData).
 
startx() ->
spawn (ddb,run,[]).