跳到主要内容
版本:release

archive -- 归档(打包文件夹)为zip/pak

概述

对文件夹中的内容打包归档为zip或pak格式的文件

参见复杂数据类型-archive

接口

Static

// Find an archive by path, auto create if need
archive find(string path, bool auto_create = false, string mode = "");
// Open an archive by path, the archive type will be auto detected by suffix of the file path
archive open(string path, string mode);

例子:

string name = "test.zip";
archive arch = archive.open(name, "wr");
defer
{
// Remove the arch files
if (arch)
arch.close();
// Closed the archive opened by file.read_all()
handle auto_opened = archive.find(name);
if (auto_opened)
auto_opened.close();
}

// Do pack

member

// Get the file list of dir in archive
array get_dir(string path, bool detail = false);
// Read the content of file in archive
buffer read_file(string path);
// Write the content of file in archive
bool write_file(string path, buffer buf);
/*
tree_files = {
"dir1" : {
"file1.dat" : "/data/file1.dat",
"file2.dat" : "/data/file2.dat",
...
},
"dir2" : ...,
"filex" : (buffer)... // data of filex
...
}
*/
// Pack files organized by map to a archive file
void pack_tree_files(map tree_files);
// Dump the full structure of the archive
void dump();
// Save the archive
void flush();