Instance Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
storeVar(value:fullObjects:)
Stores any Variant value in the file. If fullObjects
is true
, encoding objects is allowed (and can potentially include code).
final func storeVar(value: Variant, fullObjects: Bool = false)
Internally, this uses the same encoding mechanism as the @GlobalScope.var_to_bytes
method.
Other members in extension
Types
Type members
static func fileExists(path: String
) -> Bool Returns
true
if the file exists in the given path.static func getFileAsBytes(path: String
) -> PackedByteArray Returns the whole
path
file contents as aPackedByteArray
without any decoding.static func getFileAsString(path: String
) -> String Returns the whole
path
file contents as aString
. Text is interpreted as being UTF-8 encoded.static func getHiddenAttribute(file: String
) -> Bool Returns
true
, if filehidden
attribute is set.static func getMd5(path: String
) -> String Returns an MD5 String representing the file at the given path or an empty
String
on failure.static func getModifiedTime(file: String
) -> UInt Returns the last time the
file
was modified in Unix timestamp format, or0
on error. This Unix timestamp can be converted to another format using theTime
singleton.static func getOpenError(
) -> GodotError Returns the result of the last
open(path:flags:)
call in the current thread.static func getReadOnlyAttribute(file: String
) -> Bool Returns
true
, if fileread only
attribute is set.static func getSha256(path: String
) -> String Returns a SHA-256
String
representing the file at the given path or an emptyString
on failure.static func getUnixPermissions(file: String
) -> FileAccess.UnixPermissionFlags Returns file UNIX permissions.
static func open(path: String, flags: FileAccess.ModeFlags
) -> FileAccess? Creates a new
FileAccess
object and opens the file for writing or reading, depending on the flags.static func openCompressed(path: String, modeFlags: FileAccess.ModeFlags, compressionMode: FileAccess.CompressionMode
) -> FileAccess? Creates a new
FileAccess
object and opens a compressed file for reading or writing.static func openEncrypted(path: String, modeFlags: FileAccess.ModeFlags, key: PackedByteArray
) -> FileAccess? Creates a new
FileAccess
object and opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it.static func openEncryptedWithPass(path: String, modeFlags: FileAccess.ModeFlags, pass: String
) -> FileAccess? Creates a new
FileAccess
object and opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it.static func setReadOnlyAttribute(file: String, ro: Bool
) -> GodotError Sets file read only attribute.
static func setUnixPermissions(file: String, permissions: FileAccess.UnixPermissionFlags
) -> GodotError Sets file UNIX permissions.
class var godotClassName: StringName
Instance members
var bigEndian: Bool
If
true
, the file is read with big-endian endianness. Iffalse
, the file is read with little-endian endianness. If in doubt, leave this tofalse
as most files are written with little-endian endianness.func close(
) Closes the currently opened file and prevents subsequent read/write operations. Use
flush
to persist the data to disk without closing the file.func eofReached(
) -> Bool Returns
true
if the file cursor has already read past the end of the file.func flush(
) Writes the file’s buffer to disk. Flushing is automatically performed when the file is closed. This means you don’t need to call
flush
manually before closing a file. Still, callingflush
can be used to ensure the data is safe even if the project crashes instead of being closed gracefully.func get16(
) -> UInt16 Returns the next 16 bits from the file as an integer. See
store16(value:)
for details on what values can be stored and retrieved this way.func get32(
) -> UInt32 Returns the next 32 bits from the file as an integer. See
store32(value:)
for details on what values can be stored and retrieved this way.func get64(
) -> UInt Returns the next 64 bits from the file as an integer. See
store64(value:)
for details on what values can be stored and retrieved this way.func get8(
) -> UInt8 Returns the next 8 bits from the file as an integer. See
store8(value:)
for details on what values can be stored and retrieved this way.func getAsText(skipCr: Bool
) -> String Returns the whole file as a
String
. Text is interpreted as being UTF-8 encoded.func getBuffer(length: Int
) -> PackedByteArray Returns next
length
bytes of the file as aPackedByteArray
.func getCsvLine(delim: String
) -> PackedStringArray Returns the next value of the file in CSV (Comma-Separated Values) format. You can pass a different delimiter
delim
to use other than the default","
(comma). This delimiter must be one-character long, and cannot be a double quotation mark.func getDouble(
) -> Double Returns the next 64 bits from the file as a floating-point number.
func getError(
) -> GodotError Returns the last error that happened when trying to perform operations. Compare with the
ERR_FILE_*
constants fromGodotError
.func getFloat(
) -> Double Returns the next 32 bits from the file as a floating-point number.
func getLength(
) -> UInt Returns the size of the file in bytes.
func getLine(
) -> String Returns the next line of the file as a
String
.func getPascalString(
) -> String Returns a
String
saved in Pascal format from the file.func getPath(
) -> String Returns the path as a
String
for the current open file.func getPathAbsolute(
) -> String Returns the absolute path as a
String
for the current open file.func getPosition(
) -> UInt Returns the file cursor’s position.
func getReal(
) -> Double Returns the next bits from the file as a floating-point number.
func getVar(allowObjects: Bool
) -> Variant Returns the next
Variant
value from the file. IfallowObjects
istrue
, decoding objects is allowed.func isOpen(
) -> Bool Returns
true
if the file is currently opened.func seek(position: UInt
) Changes the file reading/writing cursor to the specified position (in bytes from the beginning of the file).
func seekEnd(position: Int
) Changes the file reading/writing cursor to the specified position (in bytes from the end of the file).
func store16(value: UInt16
) Stores an integer as 16 bits in the file.
func store32(value: UInt32
) Stores an integer as 32 bits in the file.
func store64(value: UInt
) Stores an integer as 64 bits in the file.
func store8(value: UInt8
) Stores an integer as 8 bits in the file.
func storeBuffer(PackedByteArray
) Stores the given array of bytes in the file.
func storeCsvLine(values: PackedStringArray, delim: String
) Store the given
PackedStringArray
in the file as a line formatted in the CSV (Comma-Separated Values) format. You can pass a different delimiterdelim
to use other than the default","
(comma). This delimiter must be one-character long.func storeDouble(value: Double
) Stores a floating-point number as 64 bits in the file.
func storeFloat(value: Double
) Stores a floating-point number as 32 bits in the file.
func storeLine(String
) Appends
line
to the file followed by a line return character (\n
), encoding the text as UTF-8.func storePascalString(String
) Stores the given
String
as a line in the file in Pascal format (i.e. also store the length of the string).func storeReal(value: Double
) Stores a floating-point number in the file.
func storeString(String
) Appends
string
to the file without a line return, encoding the text as UTF-8.