The Normal io API of LUA offers for reading file:read("*l"), file:read("*a") and file:read(number). But Love File only offer file:read(number). How can I read a Line and all? I had try this for reading lines:
function lines(fn)
local data = assert(love.filesystem.read(fn))
for line in string.gmatch(data, "[^\n]+") do
table.insert(result, line)
end
return result
end
It looks like your function can not support reading single Bytes. I need reading single bytes and reading single lines in the smae hadle like the io API.
If the file is not huge, read the whole file with love.filesystem.read, then either iterate over the resulting string or use string.match/string.find to locate delimiters. That should be faster than reading single bytes one by one.
Maybe a serialization lib is what you need; I wrote this library to parse arbitrary binary data from strings. It's very low level though and best suited for files that can be read at once. If the interface is too verbose or doesn't fit your use case, there are several other alternatives available (binser, bitser, struct). Searching the forum and/or github should yield some results.
Reading single bytes can be slow as hell; reading a big chunk into memory, then iterating over a memory area will always be faster than that;
That said, with string patterns, you can still extract single bytes from said loaded chunk, as well as lines and any other pattern that lua's capable of matching.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.