mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-05 14:10:19 +03:00
Currently including `zh_CN` and `es` which both have very high completion ratios. Others will be added once they reach a significant percentage too. These RST files will be used by godot-docs in place of its `classes` folder after we sync with https://github.com/godotengine/godot-docs/pull/5458. The update workflow is manual for now (example for `zh_CN`): - Build `godotengine/godot` in the branch we currently track (now `3.x`) - Run `godot --doctool -l zh_CN` - Run `cd doc && make rst LANGARG=zh_CN` - Copy `doc/_build/rst/*` to `classes/zh_CN/` here - Make sure to have `classes/zh_CN/index.rst` copied from `docs/classes`
661 lines
46 KiB
ReStructuredText
661 lines
46 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
|
|
.. DO NOT EDIT THIS FILE, but the File.xml source instead.
|
|
.. The source is found in doc/classes or modules/<name>/doc_classes.
|
|
|
|
.. _class_File:
|
|
|
|
File
|
|
====
|
|
|
|
**Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
|
|
|
|
Escriba para manejar las operaciones de lectura y escritura de archivos.
|
|
|
|
Descripción
|
|
----------------------
|
|
|
|
File type. This is used to permanently store data into the user device's file system and to read from it. This can be used to store game save data or player configuration files, for example.
|
|
|
|
Here's a sample on how to write and read from a file:
|
|
|
|
::
|
|
|
|
func save(content):
|
|
var file = File.new()
|
|
file.open("user://save_game.dat", File.WRITE)
|
|
file.store_string(content)
|
|
file.close()
|
|
|
|
func load():
|
|
var file = File.new()
|
|
file.open("user://save_game.dat", File.READ)
|
|
var content = file.get_as_text()
|
|
file.close()
|
|
return content
|
|
|
|
In the example above, the file will be saved in the user data folder as specified in the :doc:`Data paths <../tutorials/io/data_paths>` documentation.
|
|
|
|
\ **Note:** To access project resources once exported, it is recommended to use :ref:`ResourceLoader<class_ResourceLoader>` instead of the ``File`` API, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package.
|
|
|
|
\ **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 :ref:`flush<class_File_method_flush>` at regular intervals.
|
|
|
|
Tutoriales
|
|
--------------------
|
|
|
|
- :doc:`File system <../tutorials/scripting/filesystem>`
|
|
|
|
- `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
|
|
|
|
Propiedades
|
|
----------------------
|
|
|
|
+-------------------------+-----------------------------------------------------+-----------+
|
|
| :ref:`bool<class_bool>` | :ref:`endian_swap<class_File_property_endian_swap>` | ``false`` |
|
|
+-------------------------+-----------------------------------------------------+-----------+
|
|
|
|
Métodos
|
|
--------------
|
|
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`close<class_File_method_close>` **(** **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`eof_reached<class_File_method_eof_reached>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`file_exists<class_File_method_file_exists>` **(** :ref:`String<class_String>` path **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`flush<class_File_method_flush>` **(** **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_16<class_File_method_get_16>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_32<class_File_method_get_32>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_64<class_File_method_get_64>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_8<class_File_method_get_8>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_as_text<class_File_method_get_as_text>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_buffer<class_File_method_get_buffer>` **(** :ref:`int<class_int>` len **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_csv_line<class_File_method_get_csv_line>` **(** :ref:`String<class_String>` delim="," **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_double<class_File_method_get_double>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_error<class_File_method_get_error>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_float<class_File_method_get_float>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_len<class_File_method_get_len>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_line<class_File_method_get_line>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_md5<class_File_method_get_md5>` **(** :ref:`String<class_String>` path **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_modified_time<class_File_method_get_modified_time>` **(** :ref:`String<class_String>` file **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_pascal_string<class_File_method_get_pascal_string>` **(** **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_path<class_File_method_get_path>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_path_absolute<class_File_method_get_path_absolute>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_position<class_File_method_get_position>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_real<class_File_method_get_real>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_sha256<class_File_method_get_sha256>` **(** :ref:`String<class_String>` path **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Variant<class_Variant>` | :ref:`get_var<class_File_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`is_open<class_File_method_is_open>` **(** **)** |const| |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_File_method_open>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` flags **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_compressed<class_File_method_open_compressed>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`CompressionMode<enum_File_CompressionMode>` compression_mode=0 **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_encrypted<class_File_method_open_encrypted>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`PoolByteArray<class_PoolByteArray>` key **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_encrypted_with_pass<class_File_method_open_encrypted_with_pass>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`String<class_String>` pass **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`seek<class_File_method_seek>` **(** :ref:`int<class_int>` position **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`seek_end<class_File_method_seek_end>` **(** :ref:`int<class_int>` position=0 **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_16<class_File_method_store_16>` **(** :ref:`int<class_int>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_32<class_File_method_store_32>` **(** :ref:`int<class_int>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_64<class_File_method_store_64>` **(** :ref:`int<class_int>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_8<class_File_method_store_8>` **(** :ref:`int<class_int>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_buffer<class_File_method_store_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_csv_line<class_File_method_store_csv_line>` **(** :ref:`PoolStringArray<class_PoolStringArray>` values, :ref:`String<class_String>` delim="," **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_double<class_File_method_store_double>` **(** :ref:`float<class_float>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_float<class_File_method_store_float>` **(** :ref:`float<class_float>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_line<class_File_method_store_line>` **(** :ref:`String<class_String>` line **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_pascal_string<class_File_method_store_pascal_string>` **(** :ref:`String<class_String>` string **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_real<class_File_method_store_real>` **(** :ref:`float<class_float>` value **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_string<class_File_method_store_string>` **(** :ref:`String<class_String>` string **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`store_var<class_File_method_store_var>` **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)** |
|
|
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
Enumeraciones
|
|
--------------------------
|
|
|
|
.. _enum_File_ModeFlags:
|
|
|
|
.. _class_File_constant_READ:
|
|
|
|
.. _class_File_constant_WRITE:
|
|
|
|
.. _class_File_constant_READ_WRITE:
|
|
|
|
.. _class_File_constant_WRITE_READ:
|
|
|
|
enum **ModeFlags**:
|
|
|
|
- **READ** = **1** --- Opens the file for read operations. The cursor is positioned at the beginning of the file.
|
|
|
|
- **WRITE** = **2** --- Opens the file for write operations. The file is created if it does not exist, and truncated if it does.
|
|
|
|
- **READ_WRITE** = **3** --- Opens the file for read and write operations. Does not truncate the file. The cursor is positioned at the beginning of the file.
|
|
|
|
- **WRITE_READ** = **7** --- Opens the file for read and write operations. The file is created if it does not exist, and truncated if it does. The cursor is positioned at the beginning of the file.
|
|
|
|
----
|
|
|
|
.. _enum_File_CompressionMode:
|
|
|
|
.. _class_File_constant_COMPRESSION_FASTLZ:
|
|
|
|
.. _class_File_constant_COMPRESSION_DEFLATE:
|
|
|
|
.. _class_File_constant_COMPRESSION_ZSTD:
|
|
|
|
.. _class_File_constant_COMPRESSION_GZIP:
|
|
|
|
enum **CompressionMode**:
|
|
|
|
- **COMPRESSION_FASTLZ** = **0** --- Utiliza el método de compresión `FastLZ <http://fastlz.org/>`__.
|
|
|
|
- **COMPRESSION_DEFLATE** = **1** --- Utiliza el método de compresión `DEFLATE <https://en.wikipedia.org/wiki/DEFLATE>`__.
|
|
|
|
- **COMPRESSION_ZSTD** = **2** --- Utiliza el método de compresión `Zstandard <https://facebook.github.io/zstd/>`__.
|
|
|
|
- **COMPRESSION_GZIP** = **3** --- Utiliza el método de compresión `gzip <https://www.gzip.org/>`__.
|
|
|
|
Descripciones de Propiedades
|
|
--------------------------------------------------------
|
|
|
|
.. _class_File_property_endian_swap:
|
|
|
|
- :ref:`bool<class_bool>` **endian_swap**
|
|
|
|
+-----------+------------------------+
|
|
| *Default* | ``false`` |
|
|
+-----------+------------------------+
|
|
| *Setter* | set_endian_swap(value) |
|
|
+-----------+------------------------+
|
|
| *Getter* | get_endian_swap() |
|
|
+-----------+------------------------+
|
|
|
|
If ``true``, the file is read with big-endian `endianness <https://en.wikipedia.org/wiki/Endianness>`__. If ``false``, the file is read with little-endian endianness. If in doubt, leave this to ``false`` as most files are written with little-endian endianness.
|
|
|
|
\ **Note:** :ref:`endian_swap<class_File_property_endian_swap>` is only about the file format, not the CPU type. The CPU endianness doesn't affect the default endianness for files written.
|
|
|
|
\ **Note:** This is always reset to ``false`` whenever you open the file. Therefore, you must set :ref:`endian_swap<class_File_property_endian_swap>` *after* opening the file, not before.
|
|
|
|
Descripciones de Métodos
|
|
------------------------------------------------
|
|
|
|
.. _class_File_method_close:
|
|
|
|
- void **close** **(** **)**
|
|
|
|
Closes the currently opened file and prevents subsequent read/write operations. Use :ref:`flush<class_File_method_flush>` to persist the data to disk without closing the file.
|
|
|
|
----
|
|
|
|
.. _class_File_method_eof_reached:
|
|
|
|
- :ref:`bool<class_bool>` **eof_reached** **(** **)** |const|
|
|
|
|
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:
|
|
|
|
::
|
|
|
|
while file.get_position() < file.get_len():
|
|
# Read data
|
|
|
|
----
|
|
|
|
.. _class_File_method_file_exists:
|
|
|
|
- :ref:`bool<class_bool>` **file_exists** **(** :ref:`String<class_String>` path **)** |const|
|
|
|
|
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 :ref:`ResourceLoader.exists<class_ResourceLoader_method_exists>` for an alternative approach that takes resource remapping into account.
|
|
|
|
----
|
|
|
|
.. _class_File_method_flush:
|
|
|
|
- void **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 :ref:`flush<class_File_method_flush>` manually before closing a file using :ref:`close<class_File_method_close>`. Still, calling :ref:`flush<class_File_method_flush>` can be used to ensure the data is safe even if the project crashes instead of being closed gracefully.
|
|
|
|
\ **Note:** Only call :ref:`flush<class_File_method_flush>` when you actually need it. Otherwise, it will decrease performance due to constant disk writes.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_16:
|
|
|
|
- :ref:`int<class_int>` **get_16** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 16 bits del archivo como un número entero. Ver :ref:`store_16<class_File_method_store_16>` para detalles sobre qué valores pueden ser almacenados y recuperados de esta manera.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_32:
|
|
|
|
- :ref:`int<class_int>` **get_32** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 32 bits del archivo como un número entero. Ver :ref:`store_32<class_File_method_store_32>` para detalles sobre qué valores pueden ser almacenados y recuperados de esta manera.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_64:
|
|
|
|
- :ref:`int<class_int>` **get_64** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 64 bits del archivo como un entero. Ver :ref:`store_64<class_File_method_store_64>` para detalles sobre qué valores pueden ser almacenados y recuperados de esta manera.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_8:
|
|
|
|
- :ref:`int<class_int>` **get_8** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 8 bits del archivo como un entero. Ver :ref:`store_8<class_File_method_store_8>` para detalles sobre qué valores pueden ser almacenados y recuperados de esta manera.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_as_text:
|
|
|
|
- :ref:`String<class_String>` **get_as_text** **(** **)** |const|
|
|
|
|
Devuelve todo el archivo como una :ref:`String<class_String>`.
|
|
|
|
El texto se interpreta como codificado en UTF-8.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_buffer:
|
|
|
|
- :ref:`PoolByteArray<class_PoolByteArray>` **get_buffer** **(** :ref:`int<class_int>` len **)** |const|
|
|
|
|
Returns next ``len`` bytes of the file as a :ref:`PoolByteArray<class_PoolByteArray>`.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_csv_line:
|
|
|
|
- :ref:`PoolStringArray<class_PoolStringArray>` **get_csv_line** **(** :ref:`String<class_String>` delim="," **)** |const|
|
|
|
|
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.
|
|
|
|
For example, the following CSV lines are valid and will be properly parsed as two strings each:
|
|
|
|
::
|
|
|
|
Alice,"Hello, Bob!"
|
|
Bob,Alice! What a surprise!
|
|
Alice,"I thought you'd reply with ""Hello, world""."
|
|
|
|
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.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_double:
|
|
|
|
- :ref:`float<class_float>` **get_double** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 64 bits del archivo como un real.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_error:
|
|
|
|
- :ref:`Error<enum_@GlobalScope_Error>` **get_error** **(** **)** |const|
|
|
|
|
Devuelve el último error que ocurrió al intentar realizar las operaciones. Compare con las constantes ``ERR_FILE_*`` de :ref:`Error<enum_@GlobalScope_Error>`.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_float:
|
|
|
|
- :ref:`float<class_float>` **get_float** **(** **)** |const|
|
|
|
|
Devuelve los siguientes 32 bits del archivo como un número real.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_len:
|
|
|
|
- :ref:`int<class_int>` **get_len** **(** **)** |const|
|
|
|
|
Devuelve el tamaño del archivo en bytes.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_line:
|
|
|
|
- :ref:`String<class_String>` **get_line** **(** **)** |const|
|
|
|
|
Devuelve la siguiente línea del archivo como una :ref:`String<class_String>`.
|
|
|
|
El texto se interpreta como codificado en UTF-8.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_md5:
|
|
|
|
- :ref:`String<class_String>` **get_md5** **(** :ref:`String<class_String>` path **)** |const|
|
|
|
|
Devuelve una string MD5 que representa el archivo en la ruta dada o una :ref:`String<class_String>` vacía al fallar.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_modified_time:
|
|
|
|
- :ref:`int<class_int>` **get_modified_time** **(** :ref:`String<class_String>` file **)** |const|
|
|
|
|
Devuelve la última vez que se modificó el archivo ``file`` en formato de marca de tiempo unix o devuelve un :ref:`String<class_String>` "ERROR EN EL ``file``". Esta marca de tiempo unix puede ser convertida en fecha y hora usando el :ref:`OS.get_datetime_from_unix_time<class_OS_method_get_datetime_from_unix_time>`.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_pascal_string:
|
|
|
|
- :ref:`String<class_String>` **get_pascal_string** **(** **)**
|
|
|
|
Devuelve una :ref:`String<class_String>` guardada en formato Pascal del archivo.
|
|
|
|
El texto se interpreta como codificado en UTF-8.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_path:
|
|
|
|
- :ref:`String<class_String>` **get_path** **(** **)** |const|
|
|
|
|
Devuelve la ruta como una :ref:`String<class_String>` para el archivo abierto actual.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_path_absolute:
|
|
|
|
- :ref:`String<class_String>` **get_path_absolute** **(** **)** |const|
|
|
|
|
Devuelve la ruta absoluta como una :ref:`String<class_String>` para el archivo abierto actual.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_position:
|
|
|
|
- :ref:`int<class_int>` **get_position** **(** **)** |const|
|
|
|
|
Devuelve la posición del cursor del archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_real:
|
|
|
|
- :ref:`float<class_float>` **get_real** **(** **)** |const|
|
|
|
|
Devuelve los siguientes bits del archivo como un número real.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_sha256:
|
|
|
|
- :ref:`String<class_String>` **get_sha256** **(** :ref:`String<class_String>` path **)** |const|
|
|
|
|
Devuelve un SHA-256 :ref:`String<class_String>` que representa el archivo en la ruta dada o un :ref:`String<class_String>` vacío al fallar.
|
|
|
|
----
|
|
|
|
.. _class_File_method_get_var:
|
|
|
|
- :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)** |const|
|
|
|
|
Devuelve el siguiente valor :ref:`Variant<class_Variant>` del archivo. Si ``allow_objects`` es ``true``, se permite la decodificación de objetos.
|
|
|
|
\ **Advertencia:** Los objetos deserializados pueden contener código que se ejecuta. No utilice esta opción si el objeto serializado proviene de fuentes no fiables para evitar posibles amenazas a la seguridad, como la ejecución remota de código.
|
|
|
|
----
|
|
|
|
.. _class_File_method_is_open:
|
|
|
|
- :ref:`bool<class_bool>` **is_open** **(** **)** |const|
|
|
|
|
Devuelve ``true`` si el archivo está actualmente abierto.
|
|
|
|
----
|
|
|
|
.. _class_File_method_open:
|
|
|
|
- :ref:`Error<enum_@GlobalScope_Error>` **open** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` flags **)**
|
|
|
|
Abre el archivo para escribir o leer, dependiendo de las flags.
|
|
|
|
----
|
|
|
|
.. _class_File_method_open_compressed:
|
|
|
|
- :ref:`Error<enum_@GlobalScope_Error>` **open_compressed** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`CompressionMode<enum_File_CompressionMode>` compression_mode=0 **)**
|
|
|
|
Opens a compressed file for reading or writing.
|
|
|
|
\ **Note:** :ref:`open_compressed<class_File_method_open_compressed>` can only read files that were saved by Godot, not third-party compression formats. See `GitHub issue #28999 <https://github.com/godotengine/godot/issues/28999>`__ for a workaround.
|
|
|
|
----
|
|
|
|
.. _class_File_method_open_encrypted:
|
|
|
|
- :ref:`Error<enum_@GlobalScope_Error>` **open_encrypted** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`PoolByteArray<class_PoolByteArray>` key **)**
|
|
|
|
Abre un archivo encriptado en modo de escritura o lectura. Necesitas pasar una clave binaria para encriptarlo/desencriptarlo.
|
|
|
|
\ **Nota:** La clave proporcionada debe tener 32 bytes de longitud.
|
|
|
|
----
|
|
|
|
.. _class_File_method_open_encrypted_with_pass:
|
|
|
|
- :ref:`Error<enum_@GlobalScope_Error>` **open_encrypted_with_pass** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`String<class_String>` pass **)**
|
|
|
|
Abre un archivo encriptado en modo de escritura o lectura. Necesitas pasar una contraseña para encriptarlo/desencriptarlo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_seek:
|
|
|
|
- void **seek** **(** :ref:`int<class_int>` position **)**
|
|
|
|
Cambia el cursor de lectura/escritura del archivo a la posición especificada (en bytes desde el principio del archivo).
|
|
|
|
----
|
|
|
|
.. _class_File_method_seek_end:
|
|
|
|
- void **seek_end** **(** :ref:`int<class_int>` position=0 **)**
|
|
|
|
Cambia el cursor de lectura/escritura del archivo a la posición especificada (en bytes desde el final del archivo).
|
|
|
|
\ **Nota:** Se trata de un desplazamiento, por lo que debe utilizar números negativos o el cursor estará al final del archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_16:
|
|
|
|
- void **store_16** **(** :ref:`int<class_int>` value **)**
|
|
|
|
Almacena un entero como 16 bits en el archivo.
|
|
|
|
\ **Nota:** El valor ``value`` debe estar en el intervalo ``[0, 2^16 - 1]``. Cualquier otro valor se desbordará y se envolverá.
|
|
|
|
Para almacenar un entero con signo, use :ref:`store_64<class_File_method_store_64>` o almacene un entero con signo del intervalo ``[-2^15, 2^15 - 1]`` (es decir, manteniendo un bit para el signo) y calcule su signo manualmente al leer. Por ejemplo:
|
|
|
|
::
|
|
|
|
const MAX_15B = 1 << 15
|
|
const MAX_16B = 1 << 16
|
|
|
|
func unsigned16_to_signed(unsigned):
|
|
return (unsigned + MAX_15B) % MAX_16B - MAX_15B
|
|
|
|
func _ready():
|
|
var f = File.new()
|
|
f.open("user://file.dat", File.WRITE_READ)
|
|
f.store_16(-42) # Esto envuelve y almacena 65494 (2^16 - 42).
|
|
f.store_16(121) # En los límites, almacenará 121.
|
|
f.seek(0) # Vuelve al comienzo a leer el valor almacenado.
|
|
var lectura1 = f.get_16() # 65494
|
|
var lectura2 = f.get_16() # 121
|
|
var convertido1 = unsigned16_to_signed(lectura2) # -42
|
|
var convertido2 = unsigned16_to_signed(lectura2) # 121
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_32:
|
|
|
|
- void **store_32** **(** :ref:`int<class_int>` value **)**
|
|
|
|
Almacena un entero como 32 bits en el archivo.
|
|
|
|
\ **Nota:** El valor ``value`` debe estar en el intervalo ``[0, 2^32 - 1]``. Cualquier otro valor se desbordará y se envolverá.
|
|
|
|
Para almacenar un entero con signo, usa :ref:`store_64<class_File_method_store_64>`, o conviértelo manualmente (ver :ref:`store_16<class_File_method_store_16>` para un ejemplo).
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_64:
|
|
|
|
- void **store_64** **(** :ref:`int<class_int>` value **)**
|
|
|
|
Almacena un entero como 64 bits en el archivo.
|
|
|
|
\ **Nota:** El ``value`` debe estar en el intervalo ``[-2^63, 2^63 - 1]`` (es decir, ser un valor :ref:`int<class_int>` válido).
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_8:
|
|
|
|
- void **store_8** **(** :ref:`int<class_int>` value **)**
|
|
|
|
Almacena un entero como 8 bits en el archivo.
|
|
|
|
\ **Nota:** El ``value`` debe estar en el intervalo ``[0, 255]``. Cualquier otro valor se desbordará y se envolverá.
|
|
|
|
Para almacenar un entero firmado, usa :ref:`store_64<class_File_method_store_64>`, o conviértelo manualmente (ver :ref:`store_16<class_File_method_store_16>` para un ejemplo).
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_buffer:
|
|
|
|
- void **store_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
|
|
|
|
Almacena el array de bytes dados en el archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_csv_line:
|
|
|
|
- void **store_csv_line** **(** :ref:`PoolStringArray<class_PoolStringArray>` values, :ref:`String<class_String>` delim="," **)**
|
|
|
|
Store the given :ref:`PoolStringArray<class_PoolStringArray>` 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.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_double:
|
|
|
|
- void **store_double** **(** :ref:`float<class_float>` value **)**
|
|
|
|
Almacena un número de punto flotante como 64 bits en el archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_float:
|
|
|
|
- void **store_float** **(** :ref:`float<class_float>` value **)**
|
|
|
|
Almacena un número de real como 32 bits en el archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_line:
|
|
|
|
- void **store_line** **(** :ref:`String<class_String>` line **)**
|
|
|
|
Appends ``line`` to the file followed by a line return character (``\n``), encoding the text as UTF-8.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_pascal_string:
|
|
|
|
- void **store_pascal_string** **(** :ref:`String<class_String>` string **)**
|
|
|
|
Almacena la :ref:`String<class_String>` dada como una línea en el archivo en formato Pascal (es decir, también almacena la longitud de la string).
|
|
|
|
El texto será codificado como UTF-8.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_real:
|
|
|
|
- void **store_real** **(** :ref:`float<class_float>` value **)**
|
|
|
|
Almacena un número de real en el archivo.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_string:
|
|
|
|
- void **store_string** **(** :ref:`String<class_String>` string **)**
|
|
|
|
Appends ``string`` to the file without a line return, encoding the text as UTF-8.
|
|
|
|
\ **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 :ref:`store_pascal_string<class_File_method_store_pascal_string>` instead. For retrieving strings from a text file, you can use ``get_buffer(length).get_string_from_utf8()`` (if you know the length) or :ref:`get_as_text<class_File_method_get_as_text>`.
|
|
|
|
----
|
|
|
|
.. _class_File_method_store_var:
|
|
|
|
- void **store_var** **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)**
|
|
|
|
Stores any Variant value in the file. If ``full_objects`` is ``true``, encoding objects is allowed (and can potentially include code).
|
|
|
|
\ **Note:** Not all properties are included. Only properties that are configured with the :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>` flag set will be serialized. You can add a new usage flag to a property by overriding the :ref:`Object._get_property_list<class_Object_method__get_property_list>` method in your class. You can also check how property usage is configured by calling :ref:`Object._get_property_list<class_Object_method__get_property_list>`. See :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>` for the possible usage flags.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|