MTA:Eir/FileSystem/file/flush

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

This function writes all temporary buffers of a file/stream object into the output storage. This feature shall be interpreted as a hint, not a necessity. Implementations do not have to support this feature.

Syntax

boolean file:flush ()

Returns

Returns true if the file/stream has been successfully flushed, false otherwise.

Example

Click to collapse [-]
Client

This snippet writes a text into a file and flushes its buffers, while the file handle is being kept alive as a global. The MTA:Eir FileSystem implementation is encouraged to make sure that the data is written to the harddisk.

-- Open a text file to store something into.
local textFile = fileCreate( "my_poem.txt" );

-- Write a nice poem.
textFile:write(
[[Roses are red,
Violets are blue,
Blueberries are sweet,
Cupcakes are too.]]
);

-- At this point, the implementation does not have to write the buffers into the textfile.
-- If delayed, the text file will be empty if opened by an external editor.

-- Make sure the world knows about our poem.
textFile:flush();

-- Now the text-file should be filled with the data. The MTA:Eir FileSystem implementation has
-- support for buffer flushing, so the flush method should always return true if used with raw files.

-- We do not want to loose the grip to our lovely poem, so lets keep it alive, forever. <3
_G.poemFile = textFile;

FileSystem File Functions