以下是我的源码,我用源码生成的MD5和SHA1和原图用工具生成的md5,sha1码不同,请大家帮我看看,谢谢
--------------------------------------
package.path = package.path
..";./conf/lua/?.lua;"
local upload = require
"resty.upload" local resty_md5 = require "resty.md5" local
resty_sha1 = require "resty.sha1" local str = require "resty.string" local
fun = require "gcs.fun"
local chunk_size = 4096 local form =
upload:new(chunk_size) local md5 = resty_md5:new() local sha1 =
resty_sha1:new() local filename =fun.get_filename(ngx.var.path) local file
= io.open("/nginx_tmp/"..filename,"w") local file1 =
io.open("/nginx_tmp/"..filename..".md5","w")
if file == nil
then
--ngx.say(fun.get_filename(ngx.var.path,"w")) return end while
true do local typ, res, err =
form:read() if not typ
then ngx.say("failed to
read: ", err)
return end
if typ == "body"
then if file ~=nil
then
file:write(res)
md5:update(res)
sha1:update(res) end elseif typ == "eof"
then
file:close() file = nil ngx.var.md5 =
str.to_hex(md5:final()) ngx.var.sha1 =
str.to_hex(sha1:final()) md5:reset() sha1:reset() ngx.var.filename
= filename
break end end
if file1 ~=nil
then
file1:write(ngx.var.md5) file1:write(ngx.var.sha1) file1:close() file1
= nil end ------------------------------------
2012-11-17
wgm.china
发件人:lhmwzy
发送时间:2012-11-16 22:50
主题:Re: Re: [openresty]
为什么resty.md5生存的是乱码?
收件人:"openresty"<openresty@googlegroups.com>
抄送:
|