diff options
| author | ruki <[email protected]> | 2022-04-30 13:43:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-30 13:43:57 +0800 |
| commit | 3e5184e79053d3c270f63bfe9d66a5547d2efb14 (patch) | |
| tree | 12bf3cf82b06bd04725acc4ace708d20c55becf2 /xmake | |
| parent | 43339a13dfdd9ba6c3f1aeefe8f783a08173dd2f (diff) | |
add hash.md5
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/hash.lua | 14 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/hash.lua | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index cf9f2249d..88bdbe673 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -27,8 +27,22 @@ local utils = require("base/utils") local bytes = require("base/bytes") -- save metatable and builtin functions +hash._md5 = hash._md5 or hash.md5 hash._sha256 = hash._sha256 or hash.sha256 +-- make md5 from the given file or data +function hash.md5(file_or_data) + local hashstr, errors + if bytes.instance_of(file_or_data) then + local datasize = file_or_data:size() + local dataaddr = file_or_data:caddr() + hashstr, errors = hash._md5(dataaddr, datasize) + else + hashstr, errors = hash._md5(file_or_data) + end + return hashstr, errors +end + -- make sha256 from the given file or data function hash.sha256(file_or_data) local hashstr, errors diff --git a/xmake/core/sandbox/modules/hash.lua b/xmake/core/sandbox/modules/hash.lua index 9ce1465b6..c4bcba57a 100644 --- a/xmake/core/sandbox/modules/hash.lua +++ b/xmake/core/sandbox/modules/hash.lua @@ -48,6 +48,15 @@ function sandbox_hash.sha256(file_or_data) return sha256 end +-- make md5 from the given file or data +function sandbox_hash.md5(file_or_data) + local md5, errors = hash.md5(file_or_data) + if not md5 then + raise("cannot make md5 for %s, %s", file_or_data, errors or "unknown errors") + end + return md5 +end + -- return module return sandbox_hash |
