Documentation
¶
Overview ¶
This class can be used to permanently store data in the user device's file system and to read from it. This is useful for storing game save data or player configuration files.
Example: How to write and read from a file. The file named "save_game.dat" will be stored in the user data folder, as specified in the Data paths documentation:
package main import "graphics.gd/classdb/FileAccess" func SaveToFile(content string) { var file = FileAccess.Open("user://save_game.dat", FileAccess.Write) file.StoreString(content) } func LoadFromFile() string { var file = FileAccess.Open("user://save_game.dat", FileAccess.Read) var content = file.GetAsText() return content }
A graphics.gd/classdb/FileAccess instance has its own file cursor, which is the position in bytes in the file where the next read/write operation will occur. Functions such as Instance.Get8, Instance.Get16, Instance.Store8, and Instance.Store16 will move the file cursor forward by the number of bytes read/written. The file cursor can be moved to a specific position using Instance.SeekTo or Instance.SeekEnd, and its position can be retrieved using Instance.GetPosition.
A graphics.gd/classdb/FileAccess instance will close its file when the instance is freed. Since it inherits graphics.gd/classdb/RefCounted, this happens automatically when it is no longer in use. Instance.Close can be called to close it earlier. In C#, the reference must be disposed manually, which can be done with the using statement or by calling the Dispose method directly.
Note: To access project resources once exported, it is recommended to use graphics.gd/classdb/ResourceLoader instead of graphics.gd/classdb/FileAccess, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package. If using graphics.gd/classdb/FileAccess, make sure the file is included in the export by changing its import mode to Keep File (exported as is) in the Import dock, or, for files where this option is not available, change the non-resource export filter in the Export dialog to include the file's extension (e.g. *.txt).
Note: Files are automatically closed only if the process exits "normally" (such as by clicking the window manager's close button or pressing Alt + F4). If you stop the project execution by pressing F8 while the project is running, the file won't be closed as the game process will be killed. You can work around this by calling Instance.Flush at regular intervals.
Index ¶
- func FileExists(path string) bool
- func GetAccessTime(file string) int
- func GetFileAsBytes(path string) []byte
- func GetFileAsString(path string) string
- func GetHiddenAttribute(file string) bool
- func GetMd5(path string) string
- func GetModifiedTime(file string) int
- func GetOpenError() error
- func GetReadOnlyAttribute(file string) bool
- func GetSha256(path string) string
- func GetSize(file string) int
- func SetHiddenAttribute(file string, hidden bool) error
- func SetReadOnlyAttribute(file string, ro bool) error
- func SetUnixPermissions(file string, permissions UnixPermissionFlags) error
- type Advanced
- type Any
- type CompressionMode
- type Expanded
- func (self Expanded) GetAsText(skip_cr bool) string
- func (self Expanded) GetCsvLine(delim string) []string
- func (self Expanded) GetVar(allow_objects bool) any
- func (self Expanded) SeekEnd(position int)
- func (self Expanded) StoreCsvLine(values []string, delim string) bool
- func (self Expanded) StoreVar(value any, full_objects bool) bool
- type Extension
- type ID
- type Instance
- func CreateTemp(mode_flags int, prefix string, extension string, keep bool) Instance
- func CreateTempOptions(mode_flags int, prefix string, extension string, keep bool) Instance
- func New() Instance
- func Open(path string, flags ModeFlags) Instance
- func OpenCompressed(path string, mode_flags ModeFlags, compression_mode CompressionMode) Instance
- func OpenCompressedOptions(path string, mode_flags ModeFlags, compression_mode CompressionMode) Instance
- func OpenEncrypted(path string, mode_flags ModeFlags, key []byte, iv []byte) Instance
- func OpenEncryptedOptions(path string, mode_flags ModeFlags, key []byte, iv []byte) Instance
- func OpenEncryptedWithPass(path string, mode_flags ModeFlags, pass string) Instance
- func (self Instance) AsFileAccess() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) BigEndian() bool
- func (self Instance) Close()
- func (self Instance) EofReached() bool
- func (self Instance) Flush()
- func (self Instance) Get16() int
- func (self Instance) Get32() int
- func (self Instance) Get64() int
- func (self Instance) Get8() int
- func (self Instance) GetAsText() string
- func (self Instance) GetBuffer(length int) []byte
- func (self Instance) GetCsvLine() []string
- func (self Instance) GetDouble() Float.X
- func (self Instance) GetError() error
- func (self Instance) GetFloat() Float.X
- func (self Instance) GetHalf() Float.X
- func (self Instance) GetLength() int
- func (self Instance) GetLine() string
- func (self Instance) GetPascalString() string
- func (self Instance) GetPath() string
- func (self Instance) GetPathAbsolute() string
- func (self Instance) GetPosition() int
- func (self Instance) GetReal() Float.X
- func (self Instance) GetVar() any
- func (self Instance) ID() ID
- func (self Instance) IsOpen() bool
- func (self Instance) Resize(length int) error
- func (self Instance) SeekEnd()
- func (self Instance) SeekTo(position int)
- func (self Instance) SetBigEndian(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Store16(value int) bool
- func (self Instance) Store32(value int) bool
- func (self Instance) Store64(value int) bool
- func (self Instance) Store8(value int) bool
- func (self Instance) StoreBuffer(buffer []byte) bool
- func (self Instance) StoreCsvLine(values []string) bool
- func (self Instance) StoreDouble(value Float.X) bool
- func (self Instance) StoreFloat(value Float.X) bool
- func (self Instance) StoreHalf(value Float.X) bool
- func (self Instance) StoreLine(line string) bool
- func (self Instance) StorePascalString(s string) bool
- func (self Instance) StoreReal(value Float.X) bool
- func (self Instance) StoreString(s string) bool
- func (self Instance) StoreVar(value any) bool
- func (self Instance) Virtual(name string) reflect.Value
- type ModeFlags
- type UnixPermissionFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
Returns true if the file exists in the given path.
Note: Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See graphics.gd/classdb/ResourceLoader.Exists for an alternative approach that takes resource remapping into account.
For a non-static, relative equivalent, use graphics.gd/classdb/DirAccess.Instance.FileExists.
func GetAccessTime ¶
Returns the last time the 'file' was accessed in Unix timestamp format, or 0 on error. This Unix timestamp can be converted to another format using the graphics.gd/classdb/Time singleton.
func GetFileAsBytes ¶
Returns the whole 'path' file contents as a []byte without any decoding.
Returns an empty []byte if an error occurred while opening the file. You can use GetOpenError to check the error that occurred.
func GetFileAsString ¶
Returns the whole 'path' file contents as a string. Text is interpreted as being UTF-8 encoded.
Returns an empty string if an error occurred while opening the file. You can use GetOpenError to check the error that occurred.
func GetHiddenAttribute ¶
Returns true, if file hidden attribute is set.
Note: This method is implemented on iOS, BSD, macOS, and Windows.
func GetMd5 ¶
Returns an MD5 String representing the file at the given path or an empty string on failure.
func GetModifiedTime ¶
Returns the last time the 'file' was modified in Unix timestamp format, or 0 on error. This Unix timestamp can be converted to another format using the graphics.gd/classdb/Time singleton.
func GetOpenError ¶
func GetOpenError() error
Returns the result of the last Open call in the current thread.
func GetReadOnlyAttribute ¶
Returns true, if file read only attribute is set.
Note: This method is implemented on iOS, BSD, macOS, and Windows.
func GetSha256 ¶
Returns an SHA-256 string representing the file at the given path or an empty string on failure.
func SetHiddenAttribute ¶
Sets file hidden attribute.
Note: This method is implemented on iOS, BSD, macOS, and Windows.
func SetReadOnlyAttribute ¶
Sets file read only attribute.
Note: This method is implemented on iOS, BSD, macOS, and Windows.
func SetUnixPermissions ¶
func SetUnixPermissions(file string, permissions UnixPermissionFlags) error
Sets file UNIX permissions.
Note: This method is implemented on iOS, Linux/BSD, and macOS.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type CompressionMode ¶
type CompressionMode int //gd:FileAccess.CompressionMode
const ( // Uses the [FastLZ] compression method. // // [FastLZ]: https://fastlz.org/ CompressionFastlz CompressionMode = 0 // Uses the [DEFLATE] compression method. // // [DEFLATE]: https://en.wikipedia.org/wiki/DEFLATE CompressionDeflate CompressionMode = 1 // Uses the [Zstandard] compression method. // // [Zstandard]: https://facebook.github.io/zstd/ CompressionZstd CompressionMode = 2 // Uses the [gzip] compression method. // // [gzip]: https://www.gzip.org/ CompressionGzip CompressionMode = 3 // Uses the [brotli] compression method (only decompression is supported). // // [brotli]: https://github.com/google/brotli CompressionBrotli CompressionMode = 4 )
type Expanded ¶
type Expanded [1]gdclass.FileAccess
func (Expanded) GetAsText ¶
Returns the whole file as a string. Text is interpreted as being UTF-8 encoded. This ignores the file cursor and does not affect it.
If 'skip_cr' is true, carriage return characters (\r, CR) will be ignored when parsing the UTF-8, so that only line feed characters (\n, LF) represent a new line (Unix convention).
func (Expanded) GetCsvLine ¶
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.
Text is interpreted as being UTF-8 encoded. Text values must be enclosed in double quotes if they include the delimiter character. Double quotes within a text value can be escaped by doubling their occurrence. This advances the file cursor to after the newline character at the end of the line.
For example, the following CSV lines are valid and will be properly parsed as two strings each:
Note how the second line can omit the enclosing quotes as it does not include the delimiter. However it could very well use quotes, it was only written without for demonstration purposes. The third line must use "" for each quotation mark that needs to be interpreted as such instead of the end of a text value.
func (Expanded) GetVar ¶
Returns the next any value from the file. If 'allow_objects' is true, decoding objects is allowed. This advances the file cursor by the number of bytes read.
Internally, this uses the same decoding mechanism as the [graphics.gd/classdb/@GlobalScope.Instance.BytesToVar] method, as described in the Binary serialization API documentation.
Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.
func (Expanded) SeekEnd ¶
Changes the file reading/writing cursor to the specified position (in bytes from the end of the file). This changes the value returned by Instance.GetPosition.
Note: This is an offset, so you should use negative numbers or the file cursor will be at the end of the file.
func (Expanded) StoreCsvLine ¶
Store the given []string in the file as a line formatted in the 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.
Text will be encoded as UTF-8. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Expanded) StoreVar ¶
Stores any Variant value in the file. If 'full_objects' is true, encoding objects is allowed (and can potentially include code). This advances the file cursor by the number of bytes written. Returns true if the operation is successful.
Internally, this uses the same encoding mechanism as the [graphics.gd/classdb/@GlobalScope.Instance.VarToBytes] method, as described in the Binary serialization API documentation.
Note: Not all properties are included. Only properties that are configured with the [PropertyUsageStorage] flag set will be serialized. You can add a new usage flag to a property by overriding the graphics.gd/classdb/Object.Instance.GetPropertyList method in your class. You can also check how property usage is configured by calling graphics.gd/classdb/Object.Instance.GetPropertyList. See [PropertyUsageFlags] for the possible usage flags.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsFileAccess ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.FileAccess
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func CreateTemp ¶
Creates a temporary file. This file will be freed when the returned graphics.gd/classdb/FileAccess is freed.
If 'prefix' is not empty, it will be prefixed to the file name, separated by a -.
If 'extension' is not empty, it will be appended to the temporary file name.
If 'keep' is true, the file is not deleted when the returned graphics.gd/classdb/FileAccess is freed.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func CreateTempOptions ¶
Creates a temporary file. This file will be freed when the returned graphics.gd/classdb/FileAccess is freed.
If 'prefix' is not empty, it will be prefixed to the file name, separated by a -.
If 'extension' is not empty, it will be appended to the temporary file name.
If 'keep' is true, the file is not deleted when the returned graphics.gd/classdb/FileAccess is freed.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func Open ¶
Creates a new graphics.gd/classdb/FileAccess object and opens the file for writing or reading, depending on the flags.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func OpenCompressed ¶
func OpenCompressed(path string, mode_flags ModeFlags, compression_mode CompressionMode) Instance
Creates a new graphics.gd/classdb/FileAccess object and opens a compressed file for reading or writing.
Note: OpenCompressed can only read files that were saved by Godot, not third-party compression formats. See GitHub issue #28999 for a workaround.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func OpenCompressedOptions ¶
func OpenCompressedOptions(path string, mode_flags ModeFlags, compression_mode CompressionMode) Instance
Creates a new graphics.gd/classdb/FileAccess object and opens a compressed file for reading or writing.
Note: OpenCompressed can only read files that were saved by Godot, not third-party compression formats. See GitHub issue #28999 for a workaround.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func OpenEncrypted ¶
Creates a new graphics.gd/classdb/FileAccess object and opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it.
Note: The provided key must be 32 bytes long.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func OpenEncryptedOptions ¶
Creates a new graphics.gd/classdb/FileAccess object and opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it.
Note: The provided key must be 32 bytes long.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func OpenEncryptedWithPass ¶
Creates a new graphics.gd/classdb/FileAccess object and opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it.
Returns null if opening the file failed. You can use GetOpenError to check the error that occurred.
func (Instance) AsFileAccess ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) Close ¶
func (self Instance) Close()
Closes the currently opened file and prevents subsequent read/write operations. Use Instance.Flush to persist the data to disk without closing the file.
Note: graphics.gd/classdb/FileAccess will automatically close when it's freed, which happens when it goes out of scope or when it gets assigned with null. In C# the reference must be disposed after we are done using it, this can be done with the using statement or calling the Dispose method directly.
func (Instance) EofReached ¶
Returns true if the file cursor has already read past the end of the file.
Note: eof_reached() == false cannot be used to check whether there is more data available. To loop while there is more data available, use:
func (Instance) Flush ¶
func (self Instance) 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 Instance.Flush manually before closing a file. Still, calling Instance.Flush can be used to ensure the data is safe even if the project crashes instead of being closed gracefully.
Note: Only call Instance.Flush when you actually need it. Otherwise, it will decrease performance due to constant disk writes.
func (Instance) Get16 ¶
Returns the next 16 bits from the file as an integer. This advances the file cursor by 2 bytes. See Instance.Store16 for details on what values can be stored and retrieved this way.
func (Instance) Get32 ¶
Returns the next 32 bits from the file as an integer. This advances the file cursor by 4 bytes. See Instance.Store32 for details on what values can be stored and retrieved this way.
func (Instance) Get64 ¶
Returns the next 64 bits from the file as an integer. This advances the file cursor by 8 bytes. See Instance.Store64 for details on what values can be stored and retrieved this way.
func (Instance) Get8 ¶
Returns the next 8 bits from the file as an integer. This advances the file cursor by 1 byte. See Instance.Store8 for details on what values can be stored and retrieved this way.
func (Instance) GetAsText ¶
Returns the whole file as a string. Text is interpreted as being UTF-8 encoded. This ignores the file cursor and does not affect it.
If 'skip_cr' is true, carriage return characters (\r, CR) will be ignored when parsing the UTF-8, so that only line feed characters (\n, LF) represent a new line (Unix convention).
func (Instance) GetBuffer ¶
Returns next 'length' bytes of the file as a []byte. This advances the file cursor by 'length' bytes.
func (Instance) GetCsvLine ¶
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.
Text is interpreted as being UTF-8 encoded. Text values must be enclosed in double quotes if they include the delimiter character. Double quotes within a text value can be escaped by doubling their occurrence. This advances the file cursor to after the newline character at the end of the line.
For example, the following CSV lines are valid and will be properly parsed as two strings each:
Note how the second line can omit the enclosing quotes as it does not include the delimiter. However it could very well use quotes, it was only written without for demonstration purposes. The third line must use "" for each quotation mark that needs to be interpreted as such instead of the end of a text value.
func (Instance) GetDouble ¶
Returns the next 64 bits from the file as a floating-point number. This advances the file cursor by 8 bytes.
func (Instance) GetError ¶
Returns the last error that happened when trying to perform operations. Compare with the ERR_FILE_* constants from [Error].
func (Instance) GetFloat ¶
Returns the next 32 bits from the file as a floating-point number. This advances the file cursor by 4 bytes.
func (Instance) GetHalf ¶
Returns the next 16 bits from the file as a half-precision floating-point number. This advances the file cursor by 2 bytes.
func (Instance) GetLength ¶
Returns the size of the file in bytes. For a pipe, returns the number of bytes available for reading from the pipe.
func (Instance) GetLine ¶
Returns the next line of the file as a string. The returned string doesn't include newline (\n) or carriage return (\r) characters, but does include any other leading or trailing whitespace. This advances the file cursor to after the newline character at the end of the line.
Text is interpreted as being UTF-8 encoded.
func (Instance) GetPascalString ¶
Returns a string saved in Pascal format from the file, meaning that the length of the string is explicitly stored at the start. See Instance.StorePascalString. This may include newline characters. The file cursor is advanced after the bytes read.
Text is interpreted as being UTF-8 encoded.
func (Instance) GetPathAbsolute ¶
Returns the absolute path as a string for the current open file.
func (Instance) GetPosition ¶
Returns the file cursor's position in bytes from the beginning of the file. This is the file reading/writing cursor set by Instance.SeekTo or Instance.SeekEnd and advanced by read/write operations.
func (Instance) GetReal ¶
Returns the next bits from the file as a floating-point number. This advances the file cursor by either 4 or 8 bytes, depending on the precision used by the Godot build that saved the file.
If the file was saved by a Godot build compiled with the precision=single option (the default), the number of read bits for that file is 32. Otherwise, if compiled with the precision=double option, the number of read bits is 64.
func (Instance) GetVar ¶
Returns the next any value from the file. If 'allow_objects' is true, decoding objects is allowed. This advances the file cursor by the number of bytes read.
Internally, this uses the same decoding mechanism as the [graphics.gd/classdb/@GlobalScope.Instance.BytesToVar] method, as described in the Binary serialization API documentation.
Warning: Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.
func (Instance) Resize ¶
Resizes the file to a specified length. The file must be open in a mode that permits writing. If the file is extended, NUL characters are appended. If the file is truncated, all data from the end file to the original length of the file is lost.
func (Instance) SeekEnd ¶
func (self Instance) SeekEnd()
Changes the file reading/writing cursor to the specified position (in bytes from the end of the file). This changes the value returned by Instance.GetPosition.
Note: This is an offset, so you should use negative numbers or the file cursor will be at the end of the file.
func (Instance) SeekTo ¶
Changes the file reading/writing cursor to the specified position (in bytes from the beginning of the file). This changes the value returned by Instance.GetPosition.
func (Instance) SetBigEndian ¶
func (Instance) Store16 ¶
Stores an integer as 16 bits in the file. This advances the file cursor by 2 bytes. Returns true if the operation is successful.
Note: The 'value' should lie in the interval [0, 2^16 - 1]. Any other value will overflow and wrap around.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
To store a signed integer, use Instance.Store64 or store a signed integer from the interval [-2^15, 2^15 - 1] (i.e. keeping one bit for the signedness) and compute its sign manually when reading. For example:
func (Instance) Store32 ¶
Stores an integer as 32 bits in the file. This advances the file cursor by 4 bytes. Returns true if the operation is successful.
Note: The 'value' should lie in the interval [0, 2^32 - 1]. Any other value will overflow and wrap around.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
To store a signed integer, use Instance.Store64, or convert it manually (see Instance.Store16 for an example).
func (Instance) Store64 ¶
Stores an integer as 64 bits in the file. This advances the file cursor by 8 bytes. Returns true if the operation is successful.
Note: The 'value' must lie in the interval [-2^63, 2^63 - 1] (i.e. be a valid int value).
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) Store8 ¶
Stores an integer as 8 bits in the file. This advances the file cursor by 1 byte. Returns true if the operation is successful.
Note: The 'value' should lie in the interval [0, 255]. Any other value will overflow and wrap around.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
To store a signed integer, use Instance.Store64, or convert it manually (see Instance.Store16 for an example).
func (Instance) StoreBuffer ¶
Stores the given array of bytes in the file. This advances the file cursor by the number of bytes written. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreCsvLine ¶
Store the given []string in the file as a line formatted in the 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.
Text will be encoded as UTF-8. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreDouble ¶
Stores a floating-point number as 64 bits in the file. This advances the file cursor by 8 bytes. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreFloat ¶
Stores a floating-point number as 32 bits in the file. This advances the file cursor by 4 bytes. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreHalf ¶
Stores a half-precision floating-point number as 16 bits in the file. This advances the file cursor by 2 bytes. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreLine ¶
Stores 'line' in the file followed by a newline character (\n), encoding the text as UTF-8. This advances the file cursor by the length of the line, after the newline character. The amount of bytes written depends on the UTF-8 encoded bytes, which may be different from graphics.gd/classdb/String.Instance.Length which counts the number of UTF-32 codepoints. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StorePascalString ¶
Stores the given string as a line in the file in Pascal format (i.e. also store the length of the string). Text will be encoded as UTF-8. This advances the file cursor by the number of bytes written depending on the UTF-8 encoded bytes, which may be different from graphics.gd/classdb/String.Instance.Length which counts the number of UTF-32 codepoints. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreReal ¶
Stores a floating-point number in the file. This advances the file cursor by either 4 or 8 bytes, depending on the precision used by the current Godot build.
If using a Godot build compiled with the precision=single option (the default), this method will save a 32-bit float. Otherwise, if compiled with the precision=double option, this will save a 64-bit float. Returns true if the operation is successful.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreString ¶
Stores 'string' in the file without a newline character (\n), encoding the text as UTF-8. This advances the file cursor by the length of the string in UTF-8 encoded bytes, which may be different from graphics.gd/classdb/String.Instance.Length which counts the number of UTF-32 codepoints. Returns true if the operation is successful.
Note: This method is intended to be used to write text files. The string is stored as a UTF-8 encoded buffer without string length or terminating zero, which means that it can't be loaded back easily. If you want to store a retrievable string in a binary file, consider using Instance.StorePascalString instead. For retrieving strings from a text file, you can use get_buffer(length).get_string_from_utf8() (if you know the length) or Instance.GetAsText.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
func (Instance) StoreVar ¶
Stores any Variant value in the file. If 'full_objects' is true, encoding objects is allowed (and can potentially include code). This advances the file cursor by the number of bytes written. Returns true if the operation is successful.
Internally, this uses the same encoding mechanism as the [graphics.gd/classdb/@GlobalScope.Instance.VarToBytes] method, as described in the Binary serialization API documentation.
Note: Not all properties are included. Only properties that are configured with the [PropertyUsageStorage] flag set will be serialized. You can add a new usage flag to a property by overriding the graphics.gd/classdb/Object.Instance.GetPropertyList method in your class. You can also check how property usage is configured by calling graphics.gd/classdb/Object.Instance.GetPropertyList. See [PropertyUsageFlags] for the possible usage flags.
Note: If an error occurs, the resulting value of the file position indicator is indeterminate.
type ModeFlags ¶
type ModeFlags int //gd:FileAccess.ModeFlags
const ( // Opens the file for read operations. The file cursor is positioned at the beginning of the file. Read ModeFlags = 1 // Opens the file for write operations. The file is created if it does not exist, and truncated if it does. // // Note: When creating a file it must be in an already existing directory. To recursively create directories for a file path, see [graphics.gd/classdb/DirAccess.Instance.MakeDirRecursive]. Write ModeFlags = 2 // Opens the file for read and write operations. Does not truncate the file. The file cursor is positioned at the beginning of the file. ReadWrite ModeFlags = 3 // Opens the file for read and write operations. The file is created if it does not exist, and truncated if it does. The file cursor is positioned at the beginning of the file. // // Note: When creating a file it must be in an already existing directory. To recursively create directories for a file path, see [graphics.gd/classdb/DirAccess.Instance.MakeDirRecursive]. WriteRead ModeFlags = 7 )
type UnixPermissionFlags ¶
type UnixPermissionFlags int //gd:FileAccess.UnixPermissionFlags
const ( // Read for owner bit. UnixReadOwner UnixPermissionFlags = 256 // Write for owner bit. UnixWriteOwner UnixPermissionFlags = 128 // Execute for owner bit. UnixExecuteOwner UnixPermissionFlags = 64 // Read for group bit. UnixReadGroup UnixPermissionFlags = 32 // Write for group bit. UnixWriteGroup UnixPermissionFlags = 16 // Execute for group bit. UnixExecuteGroup UnixPermissionFlags = 8 // Read for other bit. UnixReadOther UnixPermissionFlags = 4 // Write for other bit. UnixWriteOther UnixPermissionFlags = 2 // Execute for other bit. UnixExecuteOther UnixPermissionFlags = 1 // Set user id on execution bit. UnixSetUserId UnixPermissionFlags = 2048 // Set group id on execution bit. UnixSetGroupId UnixPermissionFlags = 1024 // Restricted deletion (sticky) bit. UnixRestrictedDelete UnixPermissionFlags = 512 )
func GetUnixPermissions ¶
func GetUnixPermissions(file string) UnixPermissionFlags
Returns file UNIX permissions.
Note: This method is implemented on iOS, Linux/BSD, and macOS.