MTA:Eir/FileSystem/file/isReadable

From Multi Theft Auto: Wiki
Revision as of 16:43, 31 January 2014 by The GTA (talk | contribs) (Created page with "__NOTOC__ This function returns whether a stream is readable. If a stream is not readable, then all read operations should result in nil operations (they will return zero bytes r...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function returns whether a stream is readable. If a stream is not readable, then all read operations should result in nil operations (they will return zero bytes read or false if value reading). This state should be immutable across the lifetime of a file/stream class.

Syntax

boolean file.isReadable ()

Returns

Returns true if the file/stream is readable, false otherwise.

Example

Click to collapse [-]
Client

This snippet is the counterpart of the file.isWritable example. It attempts to read the header from the file, but throws an exception if it cannot be read from.

local function readHeader( theFile )
    -- Check whether we can read anything from the file.
    if not ( theFile.isReadable() ) then
        error( "fatal error: file cannot be read from" );
    end

    -- Read the generic header back into the engine.
    local headerInfo = {
        chunkSize = theFile.readUInt(),
        version = theFile.readFloat(),
        isRaw = theFile.readBoolean()
    };

    -- Return the header information.
    return headerInfo;
end

FileSystem File Functions