diff options
| author | ruki <[email protected]> | 2024-10-11 00:54:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-10-11 00:54:08 +0800 |
| commit | c189bb54bc616f219d7881c032a207fdaa385a17 (patch) | |
| tree | 558bb98806ae93e5bd085a392578371628a5d807 /xmake/core/base/hash.lua | |
| parent | 09ee92711986cb729d89c23c1802156bd335a602 (diff) | |
improve hash
Diffstat (limited to 'xmake/core/base/hash.lua')
| -rw-r--r-- | xmake/core/base/hash.lua | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index d5fa685b5..be831c205 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -31,7 +31,7 @@ hash._md5 = hash._md5 or hash.md5 hash._sha = hash._sha or hash.sha hash._xxhash = hash._xxhash or hash.xxhash --- make md5 from the given file or data +-- generate md5 from the given file or data function hash.md5(file_or_data) local hashstr, errors if bytes.instance_of(file_or_data) then @@ -44,7 +44,7 @@ function hash.md5(file_or_data) return hashstr, errors end --- make sha1 from the given file or data +-- generate sha1 from the given file or data function hash.sha1(file_or_data) local hashstr, errors if bytes.instance_of(file_or_data) then @@ -57,7 +57,7 @@ function hash.sha1(file_or_data) return hashstr, errors end --- make sha256 from the given file or data +-- generate sha256 from the given file or data function hash.sha256(file_or_data) local hashstr, errors if bytes.instance_of(file_or_data) then @@ -70,7 +70,7 @@ function hash.sha256(file_or_data) return hashstr, errors end --- make xxhash64 from the given file or data +-- generate xxhash64 from the given file or data function hash.xxhash64(file_or_data) local hashstr, errors if bytes.instance_of(file_or_data) then @@ -83,7 +83,7 @@ function hash.xxhash64(file_or_data) return hashstr, errors end --- make xxhash128 from the given file or data +-- generate xxhash128 from the given file or data function hash.xxhash128(file_or_data) local hashstr, errors if bytes.instance_of(file_or_data) then @@ -96,10 +96,20 @@ function hash.xxhash128(file_or_data) return hashstr, errors end --- make uuid +-- generate uuid, e.g "91E8ECF1-417F-4EDF-A574-E22D7D8D204A" function hash.uuid(str) return hash.uuid4(str) end +-- generate hash32, e.g. "91e8ecf1" +function hash.hash32(str) + return hash.uuid4(str):split("-", {plain = true})[1]:lower() +end + +-- generate hash128, e.g. "91e8ecf1417f4edfa574e22d7d8d204a" +function hash.hash128(str) + return hash.uuid4(str):replace("-", "", {plain = true}):lower() +end + -- return module: hash return hash |
