FileFlush: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: bool fileFlush ( file ) Flushes a file so that waiting disk writings are written immediately. Things written by fileWrite is often delayed until a certain buffer is full or the file is cl...)
 
No edit summary
Line 1: Line 1:
bool fileFlush ( file )
__NOTOC__
{{Server function}}


Flushes a file so that waiting disk writings are written immediately. Things written by fileWrite is often delayed until a certain buffer is full or the file is closed until they're actually written to the disk. Call this if you need the data written right now without closing the file.
Forces pending disk writes to be executed. [[fileWrite]] doesn't directly write to the hard disk but places the data in a temporary buffer; only when there is enough data in the buffer it is actually written to disk. Call this function if you need the data written right now without closing the file.
 
==Syntax==
<syntaxhighlight lang="lua">
bool fileFlush ( file theFile )
</syntaxhighlight>
 
===Required Arguments===
*'''theFile:''' The file handle of the file you wish to flush.
 
===Returns===
Returns ''true'' if succeeded, ''false'' in case of failure (e.g. the file handle is invalid).
 
==Example==
<syntaxhighlight lang="lua">
local fileHandle = fileCreate("test.txt")
if fileHandle then
    fileWrite(fileHandle, "Line 1")
    fileFlush(fileHandle)
    -- ... further writing operations
    fileClose(fileHandle)
end
</syntaxhighlight>
 
Note that [[fileClose]] automatically flushes the file.
 
==See Also==
{{File functions}}

Revision as of 11:24, 24 November 2007

Forces pending disk writes to be executed. fileWrite doesn't directly write to the hard disk but places the data in a temporary buffer; only when there is enough data in the buffer it is actually written to disk. Call this function if you need the data written right now without closing the file.

Syntax

bool fileFlush ( file theFile )

Required Arguments

  • theFile: The file handle of the file you wish to flush.

Returns

Returns true if succeeded, false in case of failure (e.g. the file handle is invalid).

Example

local fileHandle = fileCreate("test.txt")
if fileHandle then
    fileWrite(fileHandle, "Line 1")
    fileFlush(fileHandle)
    -- ... further writing operations
    fileClose(fileHandle)
end

Note that fileClose automatically flushes the file.

See Also