Modules/FileSystem/file/isReadable: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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 read or false if value reading). This state should be immutable across the lifetime of a file/stream class. ==Syntax== <syntaxhighlight lang="lua"> boolean file:isReadable () </syntaxhighlight> ==Returns== Returns '''true''' if the file/stream is readable, '''false''' otherwise. ==Example== <se...")
 
No edit summary
 
Line 1: Line 1:
<pageclass class="#3cc882" subcaption="File function"></pageclass>
__NOTOC__
__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 read or false if value reading). This state should be immutable across the lifetime of a file/stream class.
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.

Latest revision as of 03:14, 23 January 2022

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