summaryrefslogtreecommitdiff
path: root/src/index.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-10-25 23:56:41 +0200
committerMagnus Ahltorp <map@kth.se>2014-10-25 23:56:41 +0200
commitebc9d5bac1a69ba25044a73674b8e9ea18217f60 (patch)
tree3c823426f58139419d1418075252982b4da6ef95 /src/index.erl
parent2483f0cf09ccc4cf73558c7a85bbb51a72d29c3a (diff)
Optimize fetchnewentries
Diffstat (limited to 'src/index.erl')
-rw-r--r--src/index.erl11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/index.erl b/src/index.erl
index bbc9a10..c1e0352 100644
--- a/src/index.erl
+++ b/src/index.erl
@@ -77,6 +77,17 @@ decodedata(<<_:?ENTRYSIZE/binary-unit:16, _>>, _Acc) ->
util:exit_with_error(badformat, readindex,
"Index line not ending with linefeed").
+-spec size(string()) -> integer().
+size(Basepath) ->
+ case file:open(Basepath, [read, binary]) of
+ {ok, File} ->
+ {ok, Filesize} = file:position(File, eof),
+ Filesize mod ?ENTRYSIZEINFILE;
+ {error, Error} ->
+ util:exit_with_error(Error, readfile,
+ "Error opening file for reading")
+ end.
+
-spec get(string(), integer()) -> binary().
get(Basepath, Index) ->
case getrange(Basepath, Index, Index) of