MTA:Eir/FileSystem/file/read

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This function attempts to read the specified amount of bytes from the file. The actual amount of bytes read equals to the length of the Lua string.

Syntax

string file:read ( int readCount )

Arguments

  • readCount: the amount of bytes to read from the file

Returns

This function returns a string that contains the bytes that have been read from the file.

Example

Click to collapse [-]
Client

This snippet returns whether the file that is passed to it looks like a collision file.

local function isCollisionFile( file )
    -- Check whether the file is big enough to be a collision file.
    if ( ( file:size() - file:tell() ) <= 8 ) then
        return false;
    end

    -- Read the header checksum from the file.
    local checksum = file:read( 4 );

    -- Check whether the checksum is correct.
    return ( checksum == "COLL" ) or ( checksum == "COL2" ) or ( checksum == "COL3" ) or ( checksum == "COL4" );
end

-- Verify a collision file.
local myColFile = fileOpen( "collisions/fence.col" );
local result = false;

if ( myColFile ) then
    result = isCollisionFile( myColFile );

    myColFile:destroy();
end

outputChatBox( "proper collision of fence model: " .. result );

FileSystem Translator Functions

FileSystem File Functions