lua-users home
lua-l archive

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


It seems to be impossible to detect if read('line*') stopped on an
newline or fileend. Example:

input1: "blah blah" is 9 Bytes ending without a newline
input2: "blah blah\n" is 10 Bytes ending with a newline

Note that I am wrote input and not file. Because if its a file I can
check the filesize and so detect if the last byte of the file is an \n
or an other char. But what if I read from io.stdin?

Ok next try read('all*') it reads the whole stuff and its fast. But I
don't like to use it here because most of the time the incomming data
from io.stdin is only a few kilobytes but possible are also 20,30,40...
Megabytes at once and I am not ensure that my process owns enough
memory. Furthermore what if more streams are processed at the same time?
Ok I can program also an read(buffersize) _without *line_ and then
process this buffer in lines using gsub. But I feel very uncomfortable
becaus the end can be found in buffer, not found in buffer or
truncated due buffering... :-(

Back to the facts:

The input stream is divided in lines so its exaclty what I need. But how
I can check if the last byte was an \n or an other char?



--
Markus