mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
251 lines
9.3 KiB
ReStructuredText
251 lines
9.3 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. _class_ZIPPacker:
|
|
|
|
ZIPPacker
|
|
=========
|
|
|
|
**繼承:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
|
|
|
Allows the creation of ZIP files.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
說明
|
|
----
|
|
|
|
This class implements a writer that allows storing the multiple blobs in a ZIP archive. See also :ref:`ZIPReader<class_ZIPReader>` and :ref:`PCKPacker<class_PCKPacker>`.
|
|
|
|
::
|
|
|
|
# Create a ZIP archive with a single file at its root.
|
|
func write_zip_file():
|
|
var writer = ZIPPacker.new()
|
|
var err = writer.open("user://archive.zip")
|
|
if err != OK:
|
|
return err
|
|
writer.start_file("hello.txt")
|
|
writer.write_file("Hello World".to_utf8_buffer())
|
|
writer.close_file()
|
|
|
|
writer.close()
|
|
return OK
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
屬性
|
|
----
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-----------------------+----------------------------------------------------------------------+--------+
|
|
| :ref:`int<class_int>` | :ref:`compression_level<class_ZIPPacker_property_compression_level>` | ``-1`` |
|
|
+-----------------------+----------------------------------------------------------------------+--------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
方法
|
|
----
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`close<class_ZIPPacker_method_close>`\ (\ ) |
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`close_file<class_ZIPPacker_method_close_file>`\ (\ ) |
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_ZIPPacker_method_open>`\ (\ path\: :ref:`String<class_String>`, append\: :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` = 0\ ) |
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start_file<class_ZIPPacker_method_start_file>`\ (\ path\: :ref:`String<class_String>`\ ) |
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`write_file<class_ZIPPacker_method_write_file>`\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
|
|
+---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
列舉
|
|
----
|
|
|
|
.. _enum_ZIPPacker_ZipAppend:
|
|
|
|
.. rst-class:: classref-enumeration
|
|
|
|
enum **ZipAppend**: :ref:`🔗<enum_ZIPPacker_ZipAppend>`
|
|
|
|
.. _class_ZIPPacker_constant_APPEND_CREATE:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_CREATE** = ``0``
|
|
|
|
在給定的路徑新建 Zip 歸檔檔。
|
|
|
|
.. _class_ZIPPacker_constant_APPEND_CREATEAFTER:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_CREATEAFTER** = ``1``
|
|
|
|
在位於給定路徑的已有檔的末尾追加新的 Zip 歸檔檔。
|
|
|
|
.. _class_ZIPPacker_constant_APPEND_ADDINZIP:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_ADDINZIP** = ``2``
|
|
|
|
在位於給定路徑的已有 Zip 歸檔檔中新增新檔。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _enum_ZIPPacker_CompressionLevel:
|
|
|
|
.. rst-class:: classref-enumeration
|
|
|
|
enum **CompressionLevel**: :ref:`🔗<enum_ZIPPacker_CompressionLevel>`
|
|
|
|
.. _class_ZIPPacker_constant_COMPRESSION_DEFAULT:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_DEFAULT** = ``-1``
|
|
|
|
Start a file with the default Deflate compression level (``6``). This is a good compromise between speed and file size.
|
|
|
|
.. _class_ZIPPacker_constant_COMPRESSION_NONE:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_NONE** = ``0``
|
|
|
|
Start a file with no compression. This is also known as the "Store" compression mode and is the fastest method of packing files inside a ZIP archive. Consider using this mode for files that are already compressed (such as JPEG, PNG, MP3, or Ogg Vorbis files).
|
|
|
|
.. _class_ZIPPacker_constant_COMPRESSION_FAST:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_FAST** = ``1``
|
|
|
|
Start a file with the fastest Deflate compression level (``1``). This is fast to compress, but results in larger file sizes than :ref:`COMPRESSION_DEFAULT<class_ZIPPacker_constant_COMPRESSION_DEFAULT>`. Decompression speed is generally unaffected by the chosen compression level.
|
|
|
|
.. _class_ZIPPacker_constant_COMPRESSION_BEST:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_BEST** = ``9``
|
|
|
|
Start a file with the best Deflate compression level (``9``). This is slow to compress, but results in smaller file sizes than :ref:`COMPRESSION_DEFAULT<class_ZIPPacker_constant_COMPRESSION_DEFAULT>`. Decompression speed is generally unaffected by the chosen compression level.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
屬性說明
|
|
--------
|
|
|
|
.. _class_ZIPPacker_property_compression_level:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **compression_level** = ``-1`` :ref:`🔗<class_ZIPPacker_property_compression_level>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_compression_level**\ (\ value\: :ref:`int<class_int>`\ )
|
|
- :ref:`int<class_int>` **get_compression_level**\ (\ )
|
|
|
|
The compression level used when :ref:`start_file()<class_ZIPPacker_method_start_file>` is called. Use :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` as a reference.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
方法說明
|
|
--------
|
|
|
|
.. _class_ZIPPacker_method_close:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **close**\ (\ ) :ref:`🔗<class_ZIPPacker_method_close>`
|
|
|
|
關閉該實例底層所使用的資源。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_ZIPPacker_method_close_file:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **close_file**\ (\ ) :ref:`🔗<class_ZIPPacker_method_close_file>`
|
|
|
|
停止向歸檔中的檔進行寫入。
|
|
|
|
如果沒有打開檔,則會失敗。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_ZIPPacker_method_open:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **open**\ (\ path\: :ref:`String<class_String>`, append\: :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` = 0\ ) :ref:`🔗<class_ZIPPacker_method_open>`
|
|
|
|
打開給定路徑處的 Zip 檔,使用指定的寫入模式進行寫入。
|
|
|
|
必須在其他呼叫前呼叫。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_ZIPPacker_method_start_file:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **start_file**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_ZIPPacker_method_start_file>`
|
|
|
|
開始向存檔中的一個檔寫入。同一時間只能寫一個檔。
|
|
|
|
必須在\ :ref:`open()<class_ZIPPacker_method_open>`\ 之後呼叫。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_ZIPPacker_method_write_file:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **write_file**\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_ZIPPacker_method_write_file>`
|
|
|
|
將給定的 ``data`` 寫到檔案中。
|
|
|
|
需要在 :ref:`start_file()<class_ZIPPacker_method_start_file>` 之後呼叫。
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (本方法通常需要使用者覆寫才能生效。)`
|
|
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
|
.. |const| replace:: :abbr:`const (本方法沒有副作用。不會修改該實例的任何成員變數。)`
|
|
.. |vararg| replace:: :abbr:`vararg (本方法除了這裡描述的參數外,還可以接受任意數量的參數。)`
|
|
.. |constructor| replace:: :abbr:`constructor (本方法用於建構一個型別。)`
|
|
.. |static| replace:: :abbr:`static (本方法無需實例即可呼叫,因此可以直接使用類別名稱呼叫。)`
|
|
.. |operator| replace:: :abbr:`operator (本方法描述將本型別作為左運算元時可用的有效運算子。)`
|
|
.. |bitfield| replace:: :abbr:`BitField (此值是由下列旗標組成的位元遮罩整數。)`
|
|
.. |void| replace:: :abbr:`void (無回傳值。)`
|