Modules/FileSystem/file/tell: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ This function returns the current absolute position inside of the file/stream object. It should be the number of bytes that the current stream pointer is set from the beginning of the object. Not all stream classes have to support this operation. ==Syntax== <syntaxhighlight lang="lua"> int file:tell () </syntaxhighlight> ==Returns== Returns the amount of bytes that this file/stream object has already traversed. If the operation is not supported by the underly...")
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
<pageclass class="#3cc882" subcaption="File function"></pageclass>
__NOTOC__
__NOTOC__
This function returns the current absolute position inside of the file/stream object. It should be the number of bytes that the current stream pointer is set from the beginning of the object. Not all stream classes have to support this operation.
This function returns the current absolute position inside of the file/stream object. It should be the number of bytes that the current stream pointer is set from the beginning of the object. Not all stream classes have to support this operation.
Line 11: Line 12:


==Example==
==Example==
<section name="Client" class="client" show="true">
<section name="Server" class="server" show="true">
This snippet seeks back to the beginning of the file by going back the current stream pointer byte offset.
This snippet seeks back to the beginning of the file by going back the current stream pointer byte offset.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Latest revision as of 03:11, 23 January 2022

This function returns the current absolute position inside of the file/stream object. It should be the number of bytes that the current stream pointer is set from the beginning of the object. Not all stream classes have to support this operation.

Syntax

int file:tell ()

Returns

Returns the amount of bytes that this file/stream object has already traversed. If the operation is not supported by the underlying stream class, it returns false.

Example

Click to collapse [-]
Server

This snippet seeks back to the beginning of the file by going back the current stream pointer byte offset.

local function alternativeFileReset( theFile )
    -- Get the current stream position.
    local streamOffset = theFile:tell();

    -- Check whether this operation is supported.
    if not ( streamOffset ) then
        return false, "not supported";
    end

    -- Reset the file to its beginning.
    theFile:seek( -streamOffset, "cur" );
    return true;
end

FileSystem File Functions