From 5e5e1cfb0bbec60c4b886bb37796d9caa2f41878 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 6 Dec 2013 18:53:17 +0100 Subject: [PATCH] hash: Add hash_file_once() which does all the hash context work Signed-off-by: Tobias Ulmer --- generic/hash.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/generic/hash.lua b/generic/hash.lua index 8a119b8..5172f1b 100644 --- a/generic/hash.lua +++ b/generic/hash.lua @@ -127,6 +127,27 @@ function hash.hash_file(hc, path) return true end +--- Hash a file at once. +-- @param path Full path to the file. +-- @return Checksum string, or false on error. +-- @return Error object on failure. +function hash.hash_file_once(path) + local rc, re, hc, cs + + hc, re = hash.hash_start() + if not hc then + return false, re + end + + rc, re = hash.hash_file(hc, path) + if not rc then + hash.hash_finish(hc) + return false, re + end + + return hash.hash_finish(hc) +end + --- Get checksum and release hash context. -- @param hc the hash context -- @return SHA1 Checksum, or false on error. -- 2.39.5