Skip to content

Instantly share code, notes, and snippets.

@wendal
Created May 22, 2013 13:00
Show Gist options
  • Save wendal/5627360 to your computer and use it in GitHub Desktop.
Save wendal/5627360 to your computer and use it in GitHub Desktop.
nginx lua模块下的 id转特殊路径
function id2path(IN)
local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
local now = 0
local len = 0
while IN>0 do
if len > 0 and math.mod(len,2) == 0 then
OUT="/"..OUT
end
I=I+1
IN,D=math.floor(IN/B),math.mod(IN,B)+1
OUT=string.sub(K,D,D)..OUT
len = len + 1
--print(OUT.." "..now..len)
end
while len < 14 do
if len > 0 and math.mod(len,2) == 0 then
OUT="/"..OUT
end
OUT="0"..OUT
len = len + 1
end
return "/"..OUT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment