[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Difference between a+b and bit32.band(a+b)
- From: waspoza <waspoza@...>
- Date: Tue, 13 Sep 2011 10:15:15 +0200
On Mon, Sep 12, 2011 at 10:14 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> 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
On debian 64bit + luajit it gives bad checksums.
- 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
- Re: Difference between a+b and bit32.band(a+b), Roberto Ierusalimschy