lua-users home
lua-l archive

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

On Fri, Sep 9, 2011 at 18:41, Ross Berteig <> wrote:
> 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. It won't matter on Linux, but on
> Windows, the default text mode will turn all CRLF pairs into a
> single newline character, which will also disturb a checksum.
> Note that if you used io.input() to open the file (which you
> probably did since you are using io.lines() rather than
> file:lines() in your code fragment) you don't get the chance to
> set the file to binary mode.
> Ross Berteig                     
> Cheshire Engineering Corp. 

Using io.lines() to iterate binary files is also a bad idea simply for
the possibility that you encounter an extremely long "line". For
example dealing with uncompressed graphics, or large ROM images padded
to the next power-of-two size, it's not unlikely you could encounter a
run of a megabyte or more without any line break character in it.

Sent from my toaster.