Modules/FileSystem/file/size

From Multi Theft Auto: Wiki
Revision as of 03:45, 19 January 2022 by Danilo (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 () </syntaxhighlight> ==Returns== Returns the amount of bytes that this file/stream object is made of. ==Example== <section name="Client" class="client" show="true"> This snippet returns the contents of a file in a string buffer. <syntaxhighlight lang="lua"> local function fileGe...")
(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