MTA:Eir/FileSystem/file/size

From Multi Theft Auto: Wiki
Revision as of 14:32, 31 January 2014 by The GTA (talk | contribs) (Created page with "__NOTOC__ This function returns the size of a specific file/stream from beginning to end. Not all streams have to support this operation. ==Syntax== <syntaxhighlight lang="lua"> int file.size ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function returns the size of a specific file/stream from beginning to end. Not all streams have to support this operation.

Syntax

int file.size ()

Returns

Returns the amount of bytes that this file/stream object is made of.

Example

Click to collapse [-]
Client

This snippet returns the contents of a file in a string buffer.

local function fileGetContents( path )
    -- Prevent a warning being output by checking for file existance first.
    if not ( fileExists( path ) ) then return false; end;

    -- Open the requested file.
    local theFile = fileOpen( path );

    if not ( theFile ) then return false; end;

    -- The the whole content of the file into a string buffer.
    local content = theFile.read( theFile.size() );

    -- Clean up the file handle.
    theFile.destroy();
    return content;
end

FileSystem File Functions