Files
godot-docs/classes/class_zippacker.rst
2025-06-21 03:33:18 +00:00

256 lines
9.8 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/modules/zip/doc_classes/ZIPPacker.xml.
.. _class_ZIPPacker:
ZIPPacker
=========
**Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
Allows the creation of ZIP files.
.. rst-class:: classref-introduction-group
Description
-----------
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
Properties
----------
.. table::
:widths: auto
+-----------------------+----------------------------------------------------------------------+--------+
| :ref:`int<class_int>` | :ref:`compression_level<class_ZIPPacker_property_compression_level>` | ``-1`` |
+-----------------------+----------------------------------------------------------------------+--------+
.. rst-class:: classref-reftable-group
Methods
-------
.. 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
Enumerations
------------
.. _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``
Create a new zip archive at the given path.
.. _class_ZIPPacker_constant_APPEND_CREATEAFTER:
.. rst-class:: classref-enumeration-constant
:ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_CREATEAFTER** = ``1``
Append a new zip archive to the end of the already existing file at the given path.
.. _class_ZIPPacker_constant_APPEND_ADDINZIP:
.. rst-class:: classref-enumeration-constant
:ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_ADDINZIP** = ``2``
Add new files to the existing zip archive at the given path.
.. 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
Property Descriptions
---------------------
.. _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
Method Descriptions
-------------------
.. _class_ZIPPacker_method_close:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **close**\ (\ ) :ref:`🔗<class_ZIPPacker_method_close>`
Closes the underlying resources used by this instance.
.. 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>`
Stops writing to a file within the archive.
It will fail if there is no open 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>`
Opens a zip file for writing at the given path using the specified write mode.
This must be called before everything else.
.. 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>`
Starts writing to a file within the archive. Only one file can be written at the same time.
Must be called after :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>`
Write the given ``data`` to the file.
Needs to be called after :ref:`start_file()<class_ZIPPacker_method_start_file>`.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |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.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`