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 difference)
|
Revision as of 03:49, 19 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