ZIPPacker.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="ZIPPacker" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
  3. <brief_description>
  4. Allows the creation of ZIP files.
  5. </brief_description>
  6. <description>
  7. This class implements a writer that allows storing the multiple blobs in a ZIP archive. See also [ZIPReader] and [PCKPacker].
  8. [codeblock]
  9. # Create a ZIP archive with a single file at its root.
  10. func write_zip_file():
  11. var writer = ZIPPacker.new()
  12. var err = writer.open("user://archive.zip")
  13. if err != OK:
  14. return err
  15. writer.start_file("hello.txt")
  16. writer.write_file("Hello World".to_utf8_buffer())
  17. writer.close_file()
  18. writer.close()
  19. return OK
  20. [/codeblock]
  21. </description>
  22. <tutorials>
  23. </tutorials>
  24. <methods>
  25. <method name="close">
  26. <return type="int" enum="Error" />
  27. <description>
  28. Closes the underlying resources used by this instance.
  29. </description>
  30. </method>
  31. <method name="close_file">
  32. <return type="int" enum="Error" />
  33. <description>
  34. Stops writing to a file within the archive.
  35. It will fail if there is no open file.
  36. </description>
  37. </method>
  38. <method name="open">
  39. <return type="int" enum="Error" />
  40. <param index="0" name="path" type="String" />
  41. <param index="1" name="append" type="int" enum="ZIPPacker.ZipAppend" default="0" />
  42. <description>
  43. Opens a zip file for writing at the given path using the specified write mode.
  44. This must be called before everything else.
  45. </description>
  46. </method>
  47. <method name="start_file">
  48. <return type="int" enum="Error" />
  49. <param index="0" name="path" type="String" />
  50. <description>
  51. Starts writing to a file within the archive. Only one file can be written at the same time.
  52. Must be called after [method open].
  53. </description>
  54. </method>
  55. <method name="write_file">
  56. <return type="int" enum="Error" />
  57. <param index="0" name="data" type="PackedByteArray" />
  58. <description>
  59. Write the given [param data] to the file.
  60. Needs to be called after [method start_file].
  61. </description>
  62. </method>
  63. </methods>
  64. <members>
  65. <member name="compression_level" type="int" setter="set_compression_level" getter="get_compression_level" default="-1">
  66. The compression level used when [method start_file] is called. Use [enum ZIPPacker.CompressionLevel] as a reference.
  67. </member>
  68. </members>
  69. <constants>
  70. <constant name="APPEND_CREATE" value="0" enum="ZipAppend">
  71. Create a new zip archive at the given path.
  72. </constant>
  73. <constant name="APPEND_CREATEAFTER" value="1" enum="ZipAppend">
  74. Append a new zip archive to the end of the already existing file at the given path.
  75. </constant>
  76. <constant name="APPEND_ADDINZIP" value="2" enum="ZipAppend">
  77. Add new files to the existing zip archive at the given path.
  78. </constant>
  79. <constant name="COMPRESSION_DEFAULT" value="-1" enum="CompressionLevel">
  80. Start a file with the default Deflate compression level ([code]6[/code]). This is a good compromise between speed and file size.
  81. </constant>
  82. <constant name="COMPRESSION_NONE" value="0" enum="CompressionLevel">
  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. </constant>
  85. <constant name="COMPRESSION_FAST" value="1" enum="CompressionLevel">
  86. Start a file with the fastest Deflate compression level ([code]1[/code]). This is fast to compress, but results in larger file sizes than [constant COMPRESSION_DEFAULT]. Decompression speed is generally unaffected by the chosen compression level.
  87. </constant>
  88. <constant name="COMPRESSION_BEST" value="9" enum="CompressionLevel">
  89. Start a file with the the best Deflate compression level ([code]9[/code]). This is slow to compress, but results in smaller file sizes than [constant COMPRESSION_DEFAULT]. Decompression speed is generally unaffected by the chosen compression level.
  90. </constant>
  91. </constants>
  92. </class>