0.2.0-dev Download ZIP
105 lines ·5.0 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="ZIPPacker" inherits="RefCounted" api_type="core" 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 | |
| 19 | writer.close() |
| 20 | return OK |
| 21 | [/codeblock] |
| 22 | </description> |
| 23 | <tutorials> |
| 24 | </tutorials> |
| 25 | <methods> |
| 26 | <method name="add_directory"> |
| 27 | <return type="int" enum="Error" /> |
| 28 | <param index="0" name="path" type="String" /> |
| 29 | <param index="1" name="permissions" type="int" enum="FileAccess.UnixPermissionFlags" is_bitfield="true" default="493" /> |
| 30 | <param index="2" name="modified_time" type="int" default="0" /> |
| 31 | <description> |
| 32 | Adds directory to the archive. If [param modified_time] is set to [code]0[/code], current system time is used. |
| 33 | [b]Note:[/b] Directories are automatically created when [method start_file] is called, use this function before adding files to create directories with custom permissions and modification time. |
| 34 | </description> |
| 35 | </method> |
| 36 | <method name="close"> |
| 37 | <return type="int" enum="Error" /> |
| 38 | <description> |
| 39 | Closes the underlying resources used by this instance. |
| 40 | </description> |
| 41 | </method> |
| 42 | <method name="close_file"> |
| 43 | <return type="int" enum="Error" /> |
| 44 | <description> |
| 45 | Stops writing to a file within the archive. |
| 46 | It will fail if there is no open file. |
| 47 | </description> |
| 48 | </method> |
| 49 | <method name="open"> |
| 50 | <return type="int" enum="Error" /> |
| 51 | <param index="0" name="path" type="String" /> |
| 52 | <param index="1" name="append" type="int" enum="ZIPPacker.ZipAppend" default="0" /> |
| 53 | <description> |
| 54 | Opens a zip file for writing at the given path using the specified write mode. |
| 55 | This must be called before everything else. |
| 56 | </description> |
| 57 | </method> |
| 58 | <method name="start_file"> |
| 59 | <return type="int" enum="Error" /> |
| 60 | <param index="0" name="path" type="String" /> |
| 61 | <param index="1" name="permissions" type="int" enum="FileAccess.UnixPermissionFlags" is_bitfield="true" default="420" /> |
| 62 | <param index="2" name="modified_time" type="int" default="0" /> |
| 63 | <description> |
| 64 | Starts writing to a file within the archive. Only one file can be written at the same time. If [param modified_time] is set to [code]0[/code], current system time is used. |
| 65 | Must be called after [method open]. |
| 66 | </description> |
| 67 | </method> |
| 68 | <method name="write_file"> |
| 69 | <return type="int" enum="Error" /> |
| 70 | <param index="0" name="data" type="PackedByteArray" /> |
| 71 | <description> |
| 72 | Write the given [param data] to the file. |
| 73 | Needs to be called after [method start_file]. |
| 74 | </description> |
| 75 | </method> |
| 76 | </methods> |
| 77 | <members> |
| 78 | <member name="compression_level" type="int" setter="set_compression_level" getter="get_compression_level" default="-1"> |
| 79 | The compression level used when [method start_file] is called. Use [enum ZIPPacker.CompressionLevel] as a reference. |
| 80 | </member> |
| 81 | </members> |
| 82 | <constants> |
| 83 | <constant name="APPEND_CREATE" value="0" enum="ZipAppend"> |
| 84 | Create a new zip archive at the given path. |
| 85 | </constant> |
| 86 | <constant name="APPEND_CREATEAFTER" value="1" enum="ZipAppend"> |
| 87 | Append a new zip archive to the end of the already existing file at the given path. |
| 88 | </constant> |
| 89 | <constant name="APPEND_ADDINZIP" value="2" enum="ZipAppend"> |
| 90 | Add new files to the existing zip archive at the given path. |
| 91 | </constant> |
| 92 | <constant name="COMPRESSION_DEFAULT" value="-1" enum="CompressionLevel"> |
| 93 | Start a file with the default Deflate compression level ([code]6[/code]). This is a good compromise between speed and file size. |
| 94 | </constant> |
| 95 | <constant name="COMPRESSION_NONE" value="0" enum="CompressionLevel"> |
| 96 | 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). |
| 97 | </constant> |
| 98 | <constant name="COMPRESSION_FAST" value="1" enum="CompressionLevel"> |
| 99 | 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. |
| 100 | </constant> |
| 101 | <constant name="COMPRESSION_BEST" value="9" enum="CompressionLevel"> |
| 102 | Start a file with 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. |
| 103 | </constant> |
| 104 | </constants> |
| 105 | </class> |