This function returns whether the runtime can still read data from the file/stream. This is an implementation defined state that should return false if no data can be immediately received using read operations. Asynchronous file/stream objects could use this function to return true when new data is available to receive from the socket. If wanting to read an entire file/stream object, this function is more reliable than the file.size approach.
boolean file.eof ()
Returns true if data is available to be read from the file/stream object. Return false if data is not immediately available to receive from it.
This snippet is guaranteed to read an entire file/stream object.
local fileGetContentSafe( theFile ) -- Allocate a string buffer where all information is saved in. local buffer = ""; -- Read from the stream until it cannot anymore. while not ( theFile.eof() ) do buffer = buffer .. theFile.read( 1024 ); end -- At this point, some implementations could wait for data. -- Implementations are advised to use blocking I/O, implement additional Lua functions or throw exceptions. -- Clean up the file/stream handle and return the result buffer. theFile.destroy(); return buffer; end