[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Difference between a+b and bit32.band(a+b)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 12 Sep 2011 17:14:18 -0300
> 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
- References:
- Re: Difference between a+b and bit32.band(a+b), Duncan Cross
- Re: Difference between a+b and bit32.band(a+b), Luiz Henrique de Figueiredo
- Re: Difference between a+b and bit32.band(a+b), waspoza
- Re: Difference between a+b and bit32.band(a+b), Lee Hickey
- Re: Difference between a+b and bit32.band(a+b), waspoza
- Re: Difference between a+b and bit32.band(a+b), Duncan Cross
- Re: Difference between a+b and bit32.band(a+b), waspoza
- Re: Difference between a+b and bit32.band(a+b), waspoza
- Re: Difference between a+b and bit32.band(a+b), Petite Abeille
- Re: Difference between a+b and bit32.band(a+b), Ross Berteig