summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <megas.kapaneus@gmail.com>2013-04-07 19:23:35 +0200
committerPhilipp Gesang <megas.kapaneus@gmail.com>2013-04-07 19:23:35 +0200
commitabbbb9d4ddb7c864b671199cda404ad4cb33ccfa (patch)
tree8bc335d0d5a8b51888d0c24be1c0037197962059
parent83be008e1e5e06a01ca5cce672c553fe97cac4d8 (diff)
downloadlualibs-abbbb9d4ddb7c864b671199cda404ad4cb33ccfa.tar.gz
update l-md5
-rw-r--r--lualibs-md5.lua57
1 files changed, 44 insertions, 13 deletions
diff --git a/lualibs-md5.lua b/lualibs-md5.lua
index 6abf2e1..8ac20a5 100644
--- a/lualibs-md5.lua
+++ b/lualibs-md5.lua
@@ -7,29 +7,60 @@ if not modules then modules = { } end modules ['l-md5'] = {
-- This also provides file checksums and checkers.
+if not md5 then
+ md5 = optionalrequire("md5")
+end
+
+if not md5 then
+ md5 = {
+ sum = function(str) print("error: md5 is not loaded (sum ignored)") return str end,
+ sumhexa = function(str) print("error: md5 is not loaded (sumhexa ignored)") return str end,
+ }
+end
+
local md5, file = md5, file
local gsub, format, byte = string.gsub, string.format, string.byte
+local md5sum = md5.sum
local function convert(str,fmt)
- return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+ return (gsub(md5sum(str),".",function(chr) return format(fmt,byte(chr)) end))
end
if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
---~ if not md5.HEX then
---~ local function remap(chr) return format("%02X",byte(chr)) end
---~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
---~ end
---~ if not md5.hex then
---~ local function remap(chr) return format("%02x",byte(chr)) end
---~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
---~ end
---~ if not md5.dec then
---~ local function remap(chr) return format("%03i",byte(chr)) end
---~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
---~ end
+-- local P, Cs, lpegmatch = lpeg.P, lpeg.Cs,lpeg.match
+--
+-- if not md5.HEX then
+-- local function remap(chr) return format("%02X",byte(chr)) end
+-- function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+-- end
+--
+-- if not md5.hex then
+-- local function remap(chr) return format("%02x",byte(chr)) end
+-- function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+-- end
+--
+-- if not md5.dec then
+-- local function remap(chr) return format("%03i",byte(chr)) end
+-- function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+-- end
+
+-- if not md5.HEX then
+-- local pattern_HEX = Cs( ( P(1) / function(chr) return format("%02X",byte(chr)) end)^0 )
+-- function md5.HEX(str) return lpegmatch(pattern_HEX,md5.sum(str)) end
+-- end
+--
+-- if not md5.hex then
+-- local pattern_hex = Cs( ( P(1) / function(chr) return format("%02x",byte(chr)) end)^0 )
+-- function md5.hex(str) return lpegmatch(pattern_hex,md5.sum(str)) end
+-- end
+--
+-- if not md5.dec then
+-- local pattern_dec = Cs( ( P(1) / function(chr) return format("%02i",byte(chr)) end)^0 )
+-- function md5.dec(str) return lpegmatch(pattern_dec,md5.sum(str)) end
+-- end
function file.needsupdating(oldname,newname,threshold) -- size modification access change
local oldtime = lfs.attributes(oldname,"modification")