I would like to read an .ods
file line by line using lua on Windows. The code I used to do that worked on another platform but failed on Windows. So I changed the code to see what is going on:
local fhandler = io.open(path,"r")
print(pcall(fhandler.read,fhandler,"*l"))
print(pcall(fhandler.read,fhandler,"*l"))
print(pcall(fhandler.read,fhandler,"*l"))
The output I get is the following:
true <?xml version="1.0" encoding="UTF-8"?>
false function: 0x003d39e0
true :tc:opendocument:xmlns:script:1.0" [...] office:version="1.2">
So the code fails on the second line of the .ods file. I am not sure why pcall
returns a function here but the important part is, that the content of the "third" line starting with ":tc:opendoc..." belongs to the second line of the .ods file. I am pretty sure that it is the 1025 character of the second line.
I guess the following is happening: There must be a lua internal buffer of 1024 Bytes for reading whole lines. So the second line is read only till the 1024th character and then probably the buffer is full. Lua continues with reading the rest of the line. This could also explain why the code works on other platforms where the buffer might be set to another value.
I know that you can read chunks of files by specifying your own buffer like:
fhandler:read(2048,"*l")
but this does not help here because it then imports the file in 2048 Byte chunks and does not stop at the end of a line. So you would need to parse the imported data and look for line feeds etc.
So finally, my question is: Is there a lua internal buffer for the length of a line that can be read at once which may be set to 1024 Bytes? And how can you change the size of this buffer?