Modules/FileSystem/file/read: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ 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== <syntaxhighlight lang="lua"> string file:read ( int readCount ) </syntaxhighlight> ==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== <section name="Client" class="c...") |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
<pageclass class="#3cc882" subcaption="File function"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
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. | 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. | ||
Line 43: | Line 44: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
{{:Modules/FileSystem/file/functions}} | {{:Modules/FileSystem/file/functions}} |
Latest revision as of 02:57, 23 January 2022
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 [-]
ClientThis 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 );