MTA:Eir/FileSystem/file/flush: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ 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. Implementation...") |
mNo edit summary |
||
Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
boolean file | boolean file:flush () | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 18: | Line 18: | ||
-- Write a nice poem. | -- Write a nice poem. | ||
textFile | textFile:write( | ||
[[Roses are red, | [[Roses are red, | ||
Violets are blue, | Violets are blue, | ||
Line 29: | Line 29: | ||
-- Make sure the world knows about our poem. | -- Make sure the world knows about our poem. | ||
textFile | textFile:flush(); | ||
-- Now the text-file should be filled with the data. The MTA:Eir FileSystem implementation has | -- Now the text-file should be filled with the data. The MTA:Eir FileSystem implementation has |
Latest revision as of 23:49, 16 January 2022
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 [-]
ClientThis 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;