ZIPPacker

继承: RefCounted < Object

Allows the creation of zip files.

描述

This class implements a writer that allows storing the multiple blobs in a zip archive.


    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

方法


枚举

enum ZipAppend:

ZipAppend APPEND_CREATE = 0

Create a new zip archive at the given path.

ZipAppend APPEND_CREATEAFTER = 1

Append a new zip archive to the end of the already existing file at the given path.

ZipAppend APPEND_ADDINZIP = 2

Add new files to the existing zip archive at the given path.


方法说明

Error close ( )

Closes the underlying resources used by this instance.


Error close_file ( )

Stops writing to a file within the archive.

It will fail if there is no open file.


Error open ( path: String, append: ZipAppend = 0 )

Opens a zip file for writing at the given path using the specified write mode.

This must be called before everything else.


Error start_file ( path: String )

Starts writing to a file within the archive. Only one file can be written at the same time.

Must be called after open.


Error write_file ( data: PackedByteArray )

Write the given data to the file.

Needs to be called after start_file.

1

本方法通常需要用户覆盖才能生效。

2

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。