Modules/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. Implementations do not have to support this feature. ==Syntax== <syntaxhighlight lang="lua"> boolean file:flush () </syntaxhighlight> ==Returns== Returns '''true''' if the file/stream has been successfully flushed, '''false''' otherwise. ==Example== <section name="Client" class="client" show="true"> This sn...") |
No edit summary |
||
Line 1: | Line 1: | ||
<pageclass class="#3cc882" subcaption="File function"></pageclass> | |||
__NOTOC__ | __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. Implementations do not have to support this feature. | 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. |
Latest revision as of 03:13, 23 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;