Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
ZIPPacker
繼承: RefCounted < Object
Allows the creation of ZIP files.
說明
This class implements a writer that allows storing the multiple blobs in a ZIP archive. See also ZIPReader and 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
屬性
|
方法
add_directory(path: String, permissions: BitField[UnixPermissionFlags] = 493, modified_time: int = 0) |
|
close() |
|
start_file(path: String, permissions: BitField[UnixPermissionFlags] = 420, modified_time: int = 0) |
|
write_file(data: PackedByteArray) |
列舉
enum ZipAppend: 🔗
ZipAppend APPEND_CREATE = 0
在給定的路徑新建 Zip 歸檔檔。
ZipAppend APPEND_CREATEAFTER = 1
在位於給定路徑的已有檔的末尾追加新的 Zip 歸檔檔。
ZipAppend APPEND_ADDINZIP = 2
在位於給定路徑的已有 Zip 歸檔檔中新增新檔。
enum CompressionLevel: 🔗
CompressionLevel COMPRESSION_DEFAULT = -1
Start a file with the default Deflate compression level (6). This is a good compromise between speed and file size.
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).
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 COMPRESSION_DEFAULT. Decompression speed is generally unaffected by the chosen compression level.
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 COMPRESSION_DEFAULT. Decompression speed is generally unaffected by the chosen compression level.
屬性說明
The compression level used when start_file() is called. Use CompressionLevel as a reference.
方法說明
Error add_directory(path: String, permissions: BitField[UnixPermissionFlags] = 493, modified_time: int = 0) 🔗
Adds directory to the archive. If modified_time is set to 0, current system time is used.
Note: Directories are automatically created when start_file() is called, use this function before adding files to create directories with custom permissions and modification time.
關閉該實例底層所使用的資源。
停止向歸檔中的檔進行寫入。
如果沒有打開檔,則會失敗。
Error open(path: String, append: ZipAppend = 0) 🔗
打開給定路徑處的 Zip 檔,使用指定的寫入模式進行寫入。
必須在其他呼叫前呼叫。
Error start_file(path: String, permissions: BitField[UnixPermissionFlags] = 420, modified_time: int = 0) 🔗
Starts writing to a file within the archive. Only one file can be written at the same time. If modified_time is set to 0, current system time is used.
Must be called after open().
Error write_file(data: PackedByteArray) 🔗
將給定的 data 寫到檔案中。
需要在 start_file() 之後呼叫。