lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> At 05:33 PM 9/9/2011, Petite Abeille wrote:
> >> Looks like io.lines can't read binary files. :(
> >As mentioned, try the "*L" option.
> 
> And don't forget to open the file in binary mode as well,
> regardless of the Lua version.

Actually, this is the only problem. In the original code, 'io.lines' is
not reading lines, but blocks of 4K. That format should have no problems
with binary data. So, the code could be like this:

  if arg[1] then
+   local file = assert(io.open (arg[1], 'rb'))
    local x = sha2.new256()
-   for b in io.lines(arg[1], 2^12) do
+   for b in file:lines(2^12) do
      x:add(b)
    end
+   file:close()
    print(x:close())
  end

-- Roberto