MTA:Eir/FileSystem/file/isWritable

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 a stream is writable. If a stream is not writable, then all write operations should result in nil operations (they will return zero bytes written). This state should be immutable across the lifetime of a file/stream class.

Syntax

boolean file:isWritable ()

Returns

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

Example

Click to collapse [-]
Client

This snippet implements a file function that makes sure the file it has been passed to for writing actually supports writing.

local function writeHeader( theFile, headerInfo )
    -- Check whether we can write things into the file.
    if not ( theFile:isWritable() ) then
        error( "fatal error: stream is not writable" );
    end

    -- Write a generic header structure.
    theFile:writeUInt( headerInfo.chunkSize );
    theFile:writeFloat( headerInfo.version );
    theFile:writeBoolean( headerInfo.isRaw );
end

FileSystem File Functions