MTA:Eir/FileSystem/file/eof

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.

Syntax

boolean file:eof ()

Returns

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.

Example

Click to collapse [-]
Client

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

FileSystem File Functions