Add a way to get a blob's size and content

This commit is contained in:
Carlos Martín Nieto
2013-03-02 14:34:16 +01:00
parent c1660ec259
commit 7987f35e58
5 changed files with 90 additions and 2 deletions

View File

@@ -1,9 +1,12 @@
-module(geef_blob).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
-include("geef_records.hrl").
-export([lookup/2, id/1]).
-export([lookup/2, id/1, size/1, content/1]).
-spec lookup(repo(), oid() | iolist()) -> object().
lookup(Repo, Id) ->
@@ -13,3 +16,21 @@ lookup(Repo, Id) ->
-spec id(object()) -> oid().
id(Obj = #object{type=blob}) ->
geef_object:id(Obj).
size(#object{type=blob, handle=Handle}) ->
geef:blob_size(Handle).
content(#object{type=blob, handle=Handle}) ->
{ok, Content} = geef:blob_content(Handle),
Content.
-ifdef(TEST).
blob_size_test() ->
{ok, Repo} = geef_repo:open(".."),
Blob = lookup(Repo, "80d5c15a040c93a4f98f4496a05ebf30cdd58650"),
?assertMatch(889, ?MODULE:size(Blob)),
?assertMatch(889, erlang:size(content(Blob))).
-endif.