2016-11-14 44 views
1

我正在使用以下程序复制另一个文件。我经常看到源和目标不完全相同(md5sum不同)。下面的代码有什么问题吗?LUA副本问题

local size = 2^13  -- good buffer size (8K) 

local params = {...} 
local srcfile = params[1] 
local outfile = params[1] .. "_copy" 

print (srcfile) 
print (outfile) 


local inf = io.open(srcfile, "r") 
local of = io.open(outfile, "w") 

while true do 
    local block = inf:read(size) 
    print(size) 
    if not block then break end 
     of:write(block) 
end 

inf:close() 
of:close() 

感谢, GL

+0

放弃循环,只使用'of:write(inf:read(“* a”))''。 – lhf

回答

2

您可能需要使用二进制模式,以确保底线的字符不被修改。

local inf = io.open(srcfile, "rb") 
local of = io.open(outfile, "wb") 
+0

谢谢。但问题仍然存在...... – user2148707

+1

您将不得不显示数据被破坏的示例。在io.open中使用二进制模式对于Windows非常重要,并且在向文件打开模式添加“b”后,您的示例对我来说工作正常。 – Vlad

+0

完全不同的问题。与LUA无关 – user2148707