class_zippacker.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/modules/zip/doc_classes/ZIPPacker.xml.
  6. .. _class_ZIPPacker:
  7. ZIPPacker
  8. =========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Allows the creation of ZIP files.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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>`.
  15. ::
  16. # Create a ZIP archive with a single file at its root.
  17. func write_zip_file():
  18. var writer = ZIPPacker.new()
  19. var err = writer.open("user://archive.zip")
  20. if err != OK:
  21. return err
  22. writer.start_file("hello.txt")
  23. writer.write_file("Hello World".to_utf8_buffer())
  24. writer.close_file()
  25. writer.close()
  26. return OK
  27. .. rst-class:: classref-reftable-group
  28. Properties
  29. ----------
  30. .. table::
  31. :widths: auto
  32. +-----------------------+----------------------------------------------------------------------+--------+
  33. | :ref:`int<class_int>` | :ref:`compression_level<class_ZIPPacker_property_compression_level>` | ``-1`` |
  34. +-----------------------+----------------------------------------------------------------------+--------+
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`close<class_ZIPPacker_method_close>`\ (\ ) |
  42. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`close_file<class_ZIPPacker_method_close_file>`\ (\ ) |
  44. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_ZIPPacker_method_open>`\ (\ path\: :ref:`String<class_String>`, append\: :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` = 0\ ) |
  46. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start_file<class_ZIPPacker_method_start_file>`\ (\ path\: :ref:`String<class_String>`\ ) |
  48. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`write_file<class_ZIPPacker_method_write_file>`\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
  50. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  51. .. rst-class:: classref-section-separator
  52. ----
  53. .. rst-class:: classref-descriptions-group
  54. Enumerations
  55. ------------
  56. .. _enum_ZIPPacker_ZipAppend:
  57. .. rst-class:: classref-enumeration
  58. enum **ZipAppend**: :ref:`🔗<enum_ZIPPacker_ZipAppend>`
  59. .. _class_ZIPPacker_constant_APPEND_CREATE:
  60. .. rst-class:: classref-enumeration-constant
  61. :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_CREATE** = ``0``
  62. Create a new zip archive at the given path.
  63. .. _class_ZIPPacker_constant_APPEND_CREATEAFTER:
  64. .. rst-class:: classref-enumeration-constant
  65. :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_CREATEAFTER** = ``1``
  66. Append a new zip archive to the end of the already existing file at the given path.
  67. .. _class_ZIPPacker_constant_APPEND_ADDINZIP:
  68. .. rst-class:: classref-enumeration-constant
  69. :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` **APPEND_ADDINZIP** = ``2``
  70. Add new files to the existing zip archive at the given path.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _enum_ZIPPacker_CompressionLevel:
  74. .. rst-class:: classref-enumeration
  75. enum **CompressionLevel**: :ref:`🔗<enum_ZIPPacker_CompressionLevel>`
  76. .. _class_ZIPPacker_constant_COMPRESSION_DEFAULT:
  77. .. rst-class:: classref-enumeration-constant
  78. :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_DEFAULT** = ``-1``
  79. Start a file with the default Deflate compression level (``6``). This is a good compromise between speed and file size.
  80. .. _class_ZIPPacker_constant_COMPRESSION_NONE:
  81. .. rst-class:: classref-enumeration-constant
  82. :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_NONE** = ``0``
  83. 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).
  84. .. _class_ZIPPacker_constant_COMPRESSION_FAST:
  85. .. rst-class:: classref-enumeration-constant
  86. :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_FAST** = ``1``
  87. 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.
  88. .. _class_ZIPPacker_constant_COMPRESSION_BEST:
  89. .. rst-class:: classref-enumeration-constant
  90. :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` **COMPRESSION_BEST** = ``9``
  91. 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.
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Property Descriptions
  96. ---------------------
  97. .. _class_ZIPPacker_property_compression_level:
  98. .. rst-class:: classref-property
  99. :ref:`int<class_int>` **compression_level** = ``-1`` :ref:`🔗<class_ZIPPacker_property_compression_level>`
  100. .. rst-class:: classref-property-setget
  101. - |void| **set_compression_level**\ (\ value\: :ref:`int<class_int>`\ )
  102. - :ref:`int<class_int>` **get_compression_level**\ (\ )
  103. The compression level used when :ref:`start_file()<class_ZIPPacker_method_start_file>` is called. Use :ref:`CompressionLevel<enum_ZIPPacker_CompressionLevel>` as a reference.
  104. .. rst-class:: classref-section-separator
  105. ----
  106. .. rst-class:: classref-descriptions-group
  107. Method Descriptions
  108. -------------------
  109. .. _class_ZIPPacker_method_close:
  110. .. rst-class:: classref-method
  111. :ref:`Error<enum_@GlobalScope_Error>` **close**\ (\ ) :ref:`🔗<class_ZIPPacker_method_close>`
  112. Closes the underlying resources used by this instance.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_ZIPPacker_method_close_file:
  116. .. rst-class:: classref-method
  117. :ref:`Error<enum_@GlobalScope_Error>` **close_file**\ (\ ) :ref:`🔗<class_ZIPPacker_method_close_file>`
  118. Stops writing to a file within the archive.
  119. It will fail if there is no open file.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_ZIPPacker_method_open:
  123. .. rst-class:: classref-method
  124. :ref:`Error<enum_@GlobalScope_Error>` **open**\ (\ path\: :ref:`String<class_String>`, append\: :ref:`ZipAppend<enum_ZIPPacker_ZipAppend>` = 0\ ) :ref:`🔗<class_ZIPPacker_method_open>`
  125. Opens a zip file for writing at the given path using the specified write mode.
  126. This must be called before everything else.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_ZIPPacker_method_start_file:
  130. .. rst-class:: classref-method
  131. :ref:`Error<enum_@GlobalScope_Error>` **start_file**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_ZIPPacker_method_start_file>`
  132. Starts writing to a file within the archive. Only one file can be written at the same time.
  133. Must be called after :ref:`open()<class_ZIPPacker_method_open>`.
  134. .. rst-class:: classref-item-separator
  135. ----
  136. .. _class_ZIPPacker_method_write_file:
  137. .. rst-class:: classref-method
  138. :ref:`Error<enum_@GlobalScope_Error>` **write_file**\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_ZIPPacker_method_write_file>`
  139. Write the given ``data`` to the file.
  140. Needs to be called after :ref:`start_file()<class_ZIPPacker_method_start_file>`.
  141. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  142. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  143. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  144. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  145. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  146. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  147. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  148. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  149. .. |void| replace:: :abbr:`void (No return value.)`