Modules/FileSystem/file/isWritable: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ This function returns whether a stream is writable. If a stream is not writable, then all write operations should result in nil operations (they will return zero bytes written). This state should be immutable across the lifetime of a file/stream class. ==Syntax== <syntaxhighlight lang="lua"> boolean file:isWritable () </syntaxhighlight> ==Returns== Returns '''true''' if the file/stream is writable, '''false''' otherwise. ==Example== <section name="Client" cl...") |
No edit summary |
||
Line 1: | Line 1: | ||
<pageclass class="#3cc882" subcaption="File function"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
This function returns whether a stream is writable. If a stream is not writable, then all write operations should result in nil operations (they will return zero bytes written). This state should be immutable across the lifetime of a file/stream class. | This function returns whether a stream is writable. If a stream is not writable, then all write operations should result in nil operations (they will return zero bytes written). This state should be immutable across the lifetime of a file/stream class. |
Latest revision as of 03:13, 23 January 2022
This function returns whether a stream is writable. If a stream is not writable, then all write operations should result in nil operations (they will return zero bytes written). This state should be immutable across the lifetime of a file/stream class.
Syntax
boolean file:isWritable ()
Returns
Returns true if the file/stream is writable, false otherwise.
Example
Click to collapse [-]
ClientThis snippet implements a file function that makes sure the file it has been passed to for writing actually supports writing.
local function writeHeader( theFile, headerInfo ) -- Check whether we can write things into the file. if not ( theFile:isWritable() ) then error( "fatal error: stream is not writable" ); end -- Write a generic header structure. theFile:writeUInt( headerInfo.chunkSize ); theFile:writeFloat( headerInfo.version ); theFile:writeBoolean( headerInfo.isRaw ); end